我正在编写一个小型应用程序来将多个多页 PDF 转换为多页 TIFF 文件。根据该站点上的其他问题和答案,我已经尝试了 ghostscript 和 ImageMagick,但是这两个软件在我运行它们时只会隐藏第一页。是否有任何其他工具可以用来完成此任务,最好是开源工具?
2 回答
Actually Ghostscript can convert a multi-page PDF into a multi-page TIFF. Just be sure to have a rather recent version of Ghostscript installed. Be careful when examining the resulting TIFF as your viewer may not show all the pages of the TIFF or it may not be apparent how to advance to subsequent pages in the TIFF.
Consider the following 3 commands:
gs \
-o multipage-tiffg4.tif \
-sDEVICE=tiffg4 \
multipage-input.pdf
and
gs \
-o multipage-tiff24nc.tif \
-sDEVICE=tiff24nc \
multipage-input.pdf
and
gs \
-o multipage-tiff32nc.tif \
-sDEVICE=tiff32nc \
multipage-input.pdf
Each of these commands generates a multi-page TIFF, but with different output devices:
- The tiffg4 one is grayscale and uses a resolution of 204dpi by 196dpi (as the TIFF G4 fax standard requires).
- The tiff24nc one is in RGB color (with 8 bits per color component) and uses a resolution of 72dpi by 72dpi.
- The tiff32nc one is in CMYK color (with 8 bits per color) also using a resolution of 72dpi.
There are a number of additional output devices for TIFF at the link above.
All the resolution values for the TIFF files result from Ghostscript's default settings. If you want to override these, for example because you require 600dpi by 600dpi, just add
-r600x600
to any of the above commandlines.
To prove that you have multipage TIFFs, use the following command:
identify multipage-tiff*.tif
(identify
is a command from the ImageMagick package, which you seem to have installed anyway.) As a result, you should see multiple lines for each of the *.tif files -- with each line representing 1 page of the respective *.tif.
I suspect it may have worked all the way for you -- that you were just unable to recognize the multiple pages in your resulting TIFFs. Not all TIFF viewers are able to display these -- they display the first page only if they can't otherwise, which may have fooled you.
如果您有兴趣在 php 中而不是 bash 脚本中进行操作,也可以使用Imagick php 扩展。