使用Ghostscript将PNG转换为PDF

18

正如标题所说,我正在尝试将png转换为pdf。 我无法在任何地方找到关于这个的良好描述示例。

我使用了这个命令

gs sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=test.pdf test.png

但我得到的只有

Error: /syntaxerror in (binary token, type=137)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1894   1   3   %oparray_pop   1893   1   3   %oparray_pop   1877   1   3   %oparray_pop   1771   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push
Dictionary stack:
   --dict:1161/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
Current allocation mode is local
GPL Ghostscript 9.07: Unrecoverable error, exit code 1

出现了这个错误信息。现在我开始怀疑Ghostscript是否有这样的功能。我应该使用其他软件吗? ** 我正在运行最新的9.07版本


我一直使用ImageMagick来完成这个任务:将thisfile.png转换为thisfile.pdf。 - Troy Rockwood
最新的Ghostscript版本是9.10,但基于我的个人经验,我在使用您正在使用的版本时遇到了一些问题,并且这些问题在9.06版本中得到了解决,对我来说比9.07甚至9.10更稳定。 - mmoghrabi
哦,好的。Homebrew 中最新可用的版本是 9.07 版。谢谢! - Eugene Yu
2个回答

17

Ghostscript可以输出多种格式(包括PNG),但我认为它不能以PNG作为输入。不过,您可以尝试使用类似ImageMagick的convert实用程序来实现您的目标:convert test.png test.pdf


2

是的,ImageMagick可以轻松完成此任务 - 这是循环遍历文件夹中所有png并转换为pdf的命令行:

切换到包含png的文件夹

mogrify -format pdf -density 300 -units PixelsPerInch *png


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接