A compilation of documentation   { en , fr }

How to optimize a PDF document

Tag:
Created on:
Author:
Xavier Béguin

The distiller parameters of the PDF format

The Ghostscript software (that provides multiple commands such as gs, pdf2ps, or ps2pdf) allows to tune the parameters of a PDF (Portable Document Format) document.

These document parameters control the generation of the PDF document and are called distiller parameters. They can however be hard to appreciate for a non-specialist of this particular field and I find useful that the format and the software offer some predefined settings that can be used to change multiple parameters.

These presets notably allow to reduce the resolution of the document images, and thus the size of the resulting PDF document. Although this obviously usually results in a lower quality document, it can be useful to better adjust it to the intended use, such as a document intended not to be printed but to only be read on screen.

You should be aware that, contrary to my opinion about the distiller parameters presets given above, the Ghostscript documentation warns about the use of these presets if you don't understand how they alter the input document and states that it is usually better to adjust the controls individually:

The PDFSETTINGS presets should only be used if you are sure you understand that the output will be altered in a variety of ways from the input. It is usually better to adjust the controls individually (...) if you have a genuine requirement to produce, for example, a PDF file where the images are reduced in resolution.

Using these presets are thus probably not always the best thing to do, but I use them because they are practical to apply when, like me, you do not know much about the individual parameters they apply.

Applying a preset of parameters

Applying these distiller parameters presets can be achieved using a command such as this one:

gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
      -dPDFSETTINGS=/screen -sOutputFile="output.pdf" "input.pdf"

To use a different preset, adapt the option -dPDFSETTINGS=/<preset> above.

The example above uses the ebook preset, which results in a low quality (but reduced size) document. The Ghostscript documentation provides the list of available presets and the distiller parameters they apply. Below is a very broad summary of the quality level of each of these predefined settings:

  • screen: screen-view-only quality, 72 dpi images;
  • ebook: low quality, 150 dpi images;
  • printer: high quality, 300 dpi images;
  • prepress: high quality, color preserving, 300 dpi images;
  • default: almost identical to screen.

Note that I previously used another command that applies the chosen settings through a conversion to the Postscript format (on which the PDF format is based). It seems to give the same result but is considerably much slower and does not handle spaces in file names (because of the parameters substitution operated by the scripts behind ps2pdf):

pdf2ps -dLanguageLevel=3 -sOutputFile=- "input.pdf" \
    | ps2pdf -dPDFSETTINGS=/ebook -sOutputFile="output.pdf" -