1

I'm trying to reduce the file size of a PDF using GhostScript. Generally, this works:

gswin32c -sDEVICE=pdfwrite -sOutputFile=out.pdf in.pdf

I think it gets rid of bookmarks, annotations, etc.

On some PDFs, I end up with a blank PDF. I get the following output:

GPL Ghostscript 9.04 (2011-08-05)
Copyright (C) 2011 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /rangecheck in --run--
Operand stack:
   15   0   15   --nostringval--   15
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval-
-   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   fa
lse   1   %stopped_push   1926   1   3   %oparray_pop   1925   1   3   %oparray_
pop   1909   1   3   %oparray_pop   --nostringval--   --nostringval--   --nostri
ngval--   --nostringval--   --nostringval--   --nostringval--
Dictionary stack:
   --dict:1166/1684(ro)(G)--   --dict:1/20(G)--   --dict:82/200(L)--   --dict:82
/200(L)--   --dict:108/127(ro)(G)--   --dict:291/300(ro)(G)--   --dict:22/30(L)-
-
Current allocation mode is local
GPL Ghostscript 9.04: Unrecoverable error, exit code 1

The error message is not particularly helpful. Any suggestions how to troubleshoot this problem?

3 Answers 3

3

Start by using a device other than pdfwrite, You can start Ghostscript without any arguments (use the Windows version gswin32), then drag-and-drop your file on it. This will open a window to display the result.

If that works then you have probably found a bug in pdfwrite. If it doesn't then either it's a Ghostscript bug or your PDF is invalid in some way. The fact that Acrobat opens it doesn't stop it being invalid, Acorbat opens many broken PDF files....

The error message is helpful, to those who speak PostScript ;-) To those who don't, it means 'something went wrong', but if you don't understand PostScript that's about the most useful error you can expect. In this case its telling you that an operand was out of the permissible range for an operator.

You can try running with -dPDFDEBUG which will tell you what object in the PDF file caused the problem. But unless you know PDF pretty well that probably won't help you much either.

Your best bet is to open a bug report at http://bugs.ghostscript.com, you will need to attach the offending PDF file and give a command line to show the problem. If it exhibits with the display device (i.e. the window that opens when you start gswin32c.exe without any arguments to drag-and-drop files on), please supply that command line not the pdfwrite one. The assumption is that if the device is pdfwrite then its a problem in the write, which this probably isn't.

In passing, pdfwrite does not simply get rid of annotations and bookmarks, it fully interprets the PDF file to graphics primitives, and then creates a brand new PDF file which contains those graphics primitives. As a result there is no guarantee that the content of the created PDF fie is in any way similar to the content of the original. They should match in appearance but objects may well be transformed into different types.

1
  • KenS, I tried using epswrite and pswrite; I didn't get any errors from GS. I'm not sure what you mean by starting GS without any arguments, but I did drag and drop the PDF on GS. It launched a window and I could see the PDF properly (same as what I would see in Acrobat). I also ran -dPDFDEBUG, but didn't see anything out of the ordinary (though I must admit the output was very cryptic). The only thing that hints to an error is this: Error: /rangecheck in --run--. However, that was in my original post anyway. I'll post a bug report. Thanks.
    – StackOverflowNewbie
    Sep 29, 2011 at 22:05
0

Besides what KenS mentioned, be aware that XFA annotations (PDF forms generated with Adobe LifeCycle) are not supported in Ghostscript, so a file containing only these items will probably result in a blank file when processed by gswin32c.

0

Use :

gswin64c -dQUIET -dBATCH -dNOPAUSE -dSAFER -dMaxSubsetPct=100 -dPDFSETTINGS=/ebook -sDEVICE=pdfwrite -sOutputFile=outputfile.pdf inputfile.pdf

You can substitute screen or printer for ebook above - this changes the resolution of images (72/150/300 dpi)

Good luck ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .