Shrinking a PDF from the command line

From Scribus Wiki
Revision as of 22:10, 12 January 2009 by Gpittman (talk | contribs) (→‎ps2pdf)
Jump to navigation Jump to search

This is a simplified version of the method used in Web optimised PDF.

That article shows a Perl script, a rather long one at that, to accomplish the task. The actual shrinkage is accomplished by the use of pdf2ps and ps2pdf, which are utilities which come with ghostscript.

My reading of the man page for pdf2ps and a web reference for ps2pdf suggest that the first step, converting to a PostScript file, does not involve any compression. It is only in the conversion back to PDF that various settings allow for shrinking the size of the resulting file.

pdf2ps

Let's say you have a file, myfile.pdf, created by Scribus. About the only setting in pdf2pdf to consider is the language level,

pdf2ps -dLanguageLevel=3 myfile.pdf

which will create myfile.ps, and will be larger than the original PDF.

ps2pdf

On the return trip, there are many settings to consider, but for simplicity's sake you might using just one:

ps2pdf -dPDFSETTINGS=/screen myfile.ps

Or, to avoid deleting your original myfile.pdf, you might put:

ps2pdf -dPDFSETTINGS=/screen -sOutputFile=myshrunkenfile.pdf myfile.ps

The -dPDFSETTINGS option has a number of prebuilt subsettings which you will find on the above referenced webpage. Choices are /screen, /ebook, /prepress, and /printer.

If you go to the reference page, you will see a very large number of other choices for things such as image compression that you may wish to try out, but just using the /screen setting for an example 126KB file produced a 594KB PostScript file, then a final PDF of only 21KB, so only about 1/6 the size of the original. As always, check the quality of the final to see if it's adequate for your needs.