我能够将PDF的特定页面转换成PNG,代码如下:
gs \
-dSAFER \
-dBATCH \
-dNOPAUSE \
-sDEVICE=png16m \
-dGraphicsAlphaBits=4 \
-sOutputFile=gymnastics-20.png \
-dFirstPage=20 \
-dLastPage=20 \
gymnastics.pdf
我想知道是否可以使用Ghostscript的JOBSERVER模式,在不每次启动Ghostscript时处理多个转换,以避免成本。
来源:http://pages.cs.wisc.edu/~ghost/doc/svn/Use.htm
这个想法是在进程中运行Ghostscript。脚本将接收来自PDF的请求,生成指定的图片时会使用Ghostscript。我不太想每次都启动一个新的Ghostscript进程。
-dJOBSERVER
Define
\004 (^D)
to start a new encapsulated job used for compatibility with Adobe PS Interpreters that ordinarily run under a job server. The-dNOOUTERSAVE
switch is ignored if-dJOBSERVER
is specified since job servers always execute the input PostScript under a save level, although the exitserver operator can be used to escape from the encapsulated job and execute as if the-dNOOUTERSAVE
was specified.This also requires that the input be from stdin, otherwise an error will result
(
Error: /invalidrestore in --restore--
).Example usage is:
gs ... -dJOBSERVER - < inputfile.ps -or- cat inputfile.ps | gs ... -dJOBSERVER -
Note: The
^D
does not result in an end-of-file action on stdin as it may on some PostScript printers that rely on TBCP (Tagged Binary Communication Protocol) to cause an out-of-band^D
to signal EOF in a stream input data. This means that direct file actions on stdin such asflushfile
andclosefile
will affect processing of data beyond the^D
in the stream.