How to compress pdfs

Posted on August 1, 2017
Tags: howto, terminal

Often when I prepare pdfs for an application or scan documents to finally sent to someone by email, I need to reduce the file sizes. Here is an easy command using ghostscript to achieve pdf compression:

gs -sDEVICE=pdfwrite \
   -dCompatibilityLevel=1.4 \
   -dPDFSETTINGS=/printer \
   -dNOPAUSE \
   -dQUIET \
   -dBATCH \
   -sOutputFile=<output.pdf> <input.pdf>

The final quality of the output pdf can by changed with the options:

dPDFSETTINGS=/screen            # (screen-view-only quality, 72 dpi images)
dPDFSETTINGS=/ebook             # (low quality, 150 dpi images)
dPDFSETTINGS=/printer           # (high quality, 300 dpi images)
dPDFSETTINGS=/prepress          # (high quality, color preserving, 300 dpi imgs)
dPDFSETTINGS=/default           # (almost identical to /screen)


Similarly one could use imagemagick with this oneliner:

convert -units PixelsPerInch <input.pdf> -density 300 <output.pdf>