Re-encoding only PDF images? (or ghostscript crashes at 8-bit RGB during optimization)

I need to optimize several large PDF documents for file size, so I tried using it ghostscript, it gets called like this:

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

I see that this works for some pages, but then on separate pages it crashes.

I upgraded to gsversion 9.02 and I experienced the same thing. After tearing the document into separate pages and executing the above command on each page, I can confirm which pages are problematic; in fact, an error occurs even if I call only gs input-my-doc-pageX.pdf- this launches the viewer, and I could see the typing until it hit the image when it crashed.

Therefore, I could confirm that in my case it gsfalls on certain images - and finally, I can also provide a minimal working (or rather, non-working) example that demonstrates the problem (see below). In particular, the problem is 8-bit RGB images defined in a certain way.

 

Now I can’t say if this is a mistake, but since I need to do this - I thought that maybe I could "cheat" ghostscriptby running PDF files through the application, which would largely leave the PDF files untouched - for except that it will transcode images into one format (say, PNG); so that the optimizer gscan work on these files without crashing.

PDF Linux?

,
!

 

PS: : Imagemagick: PDF flate?.

, PDF (hello2.pdf) , , evince:

hello2.pdf-evince-OK

... xref- , :

$ 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
0
1

-, Ghostscript, http://bugs.ghostscript.com

-, 9.05, , , .

+2

All Articles