重新编码PDF的仅适用于图像? (或者,在ghostscript的8位RGB失败,同时优化)(R

2019-07-29 19:17发布

我需要优化的一些文件大小大的PDF文档,所以我试着用ghostscript ,调用是这样的:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH -sOutputFile=output-my-doc.pdf input-my-doc.pdf

我可以看到这个运行了一些网页,但随后在特定的网页崩溃。

我更新为gs版本9.02,和我遇到相同。 爆破将文档分成单独的页面,每个页面上运行上面的命令后,我可以确认哪些页面是有问题的人; 其实,即使我打电话只是发生错误gs input-my-doc-pageX.pdf这将启动一个浏览器,我可以看到文字排版,直到它来到了一个图像,当它崩溃- 。

所以,我可以证实,我的情况下, gs特定的图像崩溃-终于我也可以提供一个最小的工作(或者更确切地说,非工作的)例子,这表明该问题(下)。 特别地,这个问题似乎是8位RGB图像,以一定的方式指定。

 

现在,我不知道这是否是一个错误,但因为我需要得到这个工作-我在想,也许我可以“欺骗” ghostscript ,通过一个应用程序,这将几乎离开的PDF不变运行PDF文件-除了这将重新编码的图像,以一个单一的格式(比如,PNG); 从而使gs优化可能不会崩溃碾过这些文件了。

做什么选择我要重新编码只能使用在Linux命令行中给定的PDF的图像?

提前非常感谢任何答案,
干杯!

 

PS:测试用例基本上是源代码PDF示例在后: ImageMagick的:产生用于PDF flate嵌入原始图像数据? 。

这PDF( hello2.pdf )打开就好了,比方说, evince

......但因为它是外部参照表损坏,我修复它:

$ pdftk hello2.pdf output hello2O.pdf
$ qpdf --check hello2O.pdf 
checking hello2O.pdf
PDF Version: 1.4
File is not encrypted
File is not linearized
No errors found

修复的文件hello2O.pdf也打开了细evince -但是,当我尝试运行上面的gs上优化命令,它失败:

$ gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dBATCH -sOutputFile=optihello2O.pdf hello2O.pdf
GPL Ghostscript 9.02 (2011-03-30)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Loading NimbusSanL-Regu font from /usr/share/ghostscript/9.02/Resource/Font/NimbusSanL-Regu... 2756020 1410650 1869284 568021 3 done.
Error: /undefined in --run--
Operand stack:
   --dict:6/15(L)--   false   --dict:11/19(L)--   --dict:4/4(L)--   --nostringval--   FlateDecode   --dict:4/4(L)--   0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1910   1   3   %oparray_pop   1909   1   3   %oparray_pop   1893   1   3   %oparray_pop   --nostringval--   --nostringval--   2   1   1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--   --nostringval--   --nostringval--   %array_continue   --nostringval--   false   1   %stopped_push   --nostringval--   %loop_continue   --nostringval--   576   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   --nostringval--   %array_continue   --nostringval--   --nostringval--
Dictionary stack:
   --dict:1160/1684(ro)(G)--   --dict:1/20(G)--   --dict:82/200(L)--   --dict:82/200(L)--   --dict:108/127(ro)(G)--   --dict:295/300(ro)(G)--   --dict:23/30(L)--   --dict:6/8(L)--   --dict:25/40(L)--   --dict:7/17(L)--
Current allocation mode is local
GPL Ghostscript 9.02: Unrecoverable error, exit code 1

Answer 1:

首先,如果你找到一个Ghostscript的错误,请向我们举报为http://bugs.ghostscript.com

其次,我建议你更新的9.05的目前的出货版本,可能有这个bug修复。



文章来源: Re-encoding only images of a PDF? (or, ghostscript fails on 8-bit RGB while optimizing)