Ghostscript to merge PDFs compresses the result

Dimitris Baltas picture Dimitris Baltas · Nov 16, 2011 · Viewed 65.1k times · Source

I found this neat command to merge multiple PDF into one, using Ghostscript:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=out.pdf in1.pdf in2.pdf

The resulting size is smaller than the combined size of the 2 PDFs.

Running the command with a single file as input still results to a smaller size output file.

Is there an option on Ghostscript to just copy the pages as they appear on merging without doing any compression?

If not, is it possible that the Ghostscript compression is so good that it will result in absolutely no loss in quality?

Answer

Chris Haas picture Chris Haas · Nov 16, 2011

Here's some additional options that you can pass when using pdfwrite as your device. According to that page if you don't pass anything then -dPDFSETTINGS it gets set to something close to /screen, although it doesn't get more specific. You could try setting it to -dPDFSETTINGS=/prepress which should only compress things above 300 dpi.

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=out.pdf in1.pdf in2.pdf

Another alternative is pdftk:

pdftk in1.pdf in2.pdf cat output out.pdf