Portál AbcLinuxu, 2. května 2025 05:54
Výsledky své vědecké práce prezentuji z času na čas na konferencích formou tzv. posteru (tedy plakátu). Takový poster vytvářím o velikosti a0, aby byl dostatečně veliký. Pro potřeby náhledu tisku se hodí mít možnost PostScriptový dokument transformovat na různé velikosti. Možností je několik, ale jako nejrychlejší mi přišlo vytvořit si vlastní Pythonový skriptík.
Asi nejsnazší by bylo otevřít PDF dokument v Acrobat Readeru, který umí pro účely tisku dokument zmenšit. Z nějakého důvodu mi však Acrobat Reader nenabízí všechny moje nainstalované tiskárny a řešit to tiskem do souboru mi přijde nepohodlné.
Další možností je použití psresize
. Zde je však problém, že sice dojde ke zmenšení grafiky, ale zůstane v hlavičce původní nastavení velikosti plátna. psresize
navíc nepodporuje přímo papíry a0, a1 nebo a2 a je třeba ručně zadávat velikost v mm, kterou si nepamatuji.
Napsal jsem proto skript v Pythonu, který využívá služeb psresize
, ale kromě změny velikosti grafiky upraví také plátno. Podporuje přímo na příkazové řádce papíry a0 - a6.
#!/usr/bin/env python # -*- coding: utf-8 -*- ########################################### ### PS size conversion utility ### ### (C) Karel Lemr 2009 ### ### Licensed under the terms of ### ### General Public License ### ########################################### #IMPORT PYTHON MODULES try: import sys import string import os import re except StandardError: print "* E: Module loading." exit() #DEFAULT SETTING inputPaper = "a0" outputPaper = "a4" paperPortrait = True; #HELP def showHelp(): print "psconv version 1.0" print "Copyright Karel Lemr 2009, licensed under General Public License http://www.fsf.org/licensing/licenses/gpl.html" print "Usage: psconv [-l] [-P] [-p] input_file output_file" print "-l: Landscape orientation (use if your document is landscape oriented)" print "-P: Input paper type, allowed opts. are a6, a5, a4, a3, a2, a1, a0" print "-p: Output paper type, allowed opts. are a6, a5, a4, a3, a2, a1, a0" print "input_file: path to the original file" print "output_file: path to the output file" print "This program requires python interpreter and psresize program" exit() #PARSE COMMAND LINE OPTS. args = sys.argv[1:] expectInputPaper = False; expectOutputPaper = False; expectInputFile = True; for arg in args: if expectInputPaper: inputPaper = arg; expectInputPaper = False; elif expectOutputPaper: outputPaper = arg; expectOutputPaper = False; elif arg == "-P": expectInputPaper = True; elif arg == "-p": expectOutputPaper = True; elif arg == "-l": paperPortrait = False; elif arg == "-h": showHelp() elif arg == "--help": showHelp() else: if expectInputFile: inputFile = arg; expectInputFile = False; else: outputFile = arg; #PAPER TYPE -> SIZE CONVERSION FUNCTION def type2size(type, portrait): typeSizeMap = { "a6" : [105, 148], "a5" : [148, 210], "a4" : [210, 297], "a3" : [297, 420], "a2" : [420, 594], "a1" : [594, 841], "a0" : [841, 1189]} try: size = typeSizeMap[type] except StandardError: print "* E: Unknown paper size %s." % (type) exit() if not portrait: w = size[1] size = [w, size[0]] return size #PARAMS. SET&CHECK try: open(inputFile,"r").close() except StandardError: print "* E: Unable to open input file: '%s'." % (inputFile) print "Use -h switch to display syntax help." exit() try: open(outputFile,"a").close() except StandardError: print "* E: Unable to open output file for wriiting: '%s'." % (outputFile) print "Use -h switch to display syntax help." exit() inputSize = type2size(inputPaper, paperPortrait) outputSize = type2size(outputPaper, paperPortrait) #RESIZE THE GRAPHICS USING EXTERNAL psresize TOOL try: os.system("psresize -W%dmm -H%dmm -w%dmm -h%dmm %s %s" % (inputSize[0], inputSize[1], outputSize[0], outputSize[1], inputFile, outputFile)) except StandardError: print "* E: Unable to run psresize command." exit() #RESIZE THE PAPER SIZE CHANGING THE HEADER (using PS points) outputW = 596*outputSize[0]/210 outputH = 3371*outputSize[1]/1189 try: outputHandle = open(outputFile,"r") output = outputHandle.read() output = re.sub("%%BoundingBox..*","%%%%BoundingBox: 0 0 %d %d" % (outputW, outputH),output) output = re.sub("%%HiResBoundingBox..*","%%%%HiResBoundingBox: 0 0 %d %d" % (outputW, outputH),output) output = re.sub("%%DocumentMedia..*","%%%%DocumentMedia: %s %d %d 0 () ()" % (outputPaper, outputW, outputH), output) outputHandle.close() outputHandle = open(outputFile,"w") outputHandle.write(output) outputHandle.close() except StandardError: print "* E: Unable to change output file header." exit()
Tiskni
Sdílej:
# dpkg -p poster Package: poster Priority: optional Section: text Installed-Size: 84 Maintainer: Peter S Galbraith Architecture: powerpc Version: 1:20050907-1 Depends: libc6 (>= 2.7-1), libpaper1 Filename: pool/main/p/poster/poster_20050907-1_powerpc.deb Size: 25064 MD5sum: 4ffc2c35a154939b0a0bbdf82748245e Description: Create large posters out of PostScript pages Poster takes a one-page PostScript file and scales it to a specified size. It can tile the resulting image into multiple smaller pages that can be pasted together to form the big poster. Poster prefers EPS as its input although freer forms of PostScript are also understood.
No vida, tak tenhle program mi uniknul při rešerši.
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.