Sometimes you need to make an existing PDF smaller quickly. Either you miss the source for the file, or it is a lot of hassle to find the offending large objects. If large, high-resolution images are the cause of large PDF files, Ghostscript can help compress them, sacrificing image quality for size (although the results should still be acceptable).

The “basic” command line is this:

gs -dNOPAUSE -dQUIET -dBATCH -dSAFER  # those are for non-interactive
   -sDEVICE=pdfwrite                  # output a PDF
   -dPDFSETTINGS=/printer             # one of screen,ebook,printer,prepress
   -dCompatibilityLevel=1.5           # PDF v1.5
   -dEmbedAllFonts=true -dSubsetFonts=true # sane font handling
   -dAutoRotatePages=/None            # disable that
   -sOutputFile=<name of outfile>
   <name of infile>

For copy-pasting (edit input and output file names):

gs -dNOPAUSE -dQUIET -dBATCH -dSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/printer -dCompatibilityLevel=1.5 -dEmbedAllFonts=true -dSubsetFonts=true -dAutoRotatePages=/None -sOutputFile=OUTFILE.pdf INFILE.pdf

The final quality (and thereby file size) can be controlled by the -dPDFSETTINGS switch. The following options mostly control the image resolution, but also some additional settings:

  • /screen: 72 dpi

  • /ebook: 150 dpi

  • /printer: 300 dpi

  • /prepress: 300 dpi, using a higher quality downsampling algorithm, which results in a larger file

The best compromise between quality and file size is usually /printer. Any further adjustments can be made by setting the image resolution directly. Just add the following to the command line (the resolution is given as an integer representing dpi):

  -dColorImageResolution=<res>
  -dGrayImageResolution=<res>
  -dMonoImageResolution=<res>

Full command line for copy-pasting (edit the variable RES to change the resolution and the input and output file names):

RES=150; gs -dNOPAUSE -dQUIET -dBATCH -dSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/printer -dCompatibilityLevel=1.5 -dEmbedAllFonts=true -dSubsetFonts=true -dAutoRotatePages=/None -dColorImageResolution="$RES" -dGrayImageResolution="$RES" -dMonoImageResolution="$RES" -sOutputFile=OUTFILE.pdf INFILE.pdf

The downsampling algorithm can also be set:

  -dColorImageDownsampleType=<algo>
  -dGrayImageDownsampleType=<algo>
  -dMonoImageDownsampleType=<algo>

Possible values are /Subsample, /Average, or /Bicubic (these come from Adobe Distiller). Bicubic often yields better results and might yield smaller file sizes, but not always. It is best to ignore this setting unless it is really needed.