How to reduce the size of a pdf file that contains images

compressionpdf

I have a pdf file that contains images and I want to reduce its size in order to upload it to a site with a size limit.

So, how can I reduce the size of a pdf file from the command-line?

Best Answer

You can use gs - GhostScript (PostScript and PDF language interpreter and previewer) as follows:

  • Set pdfwrite as output device by -sDEVICE=pdfwrite
  • Use the appropriate -dPDFSETTINGS.

    From Documentation:

    -dPDFSETTINGS=configuration
    Presets the "distiller parameters" to one of four predefined settings:

    • /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
    • /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
    • /printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
    • /prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
    • /default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file.
  • -o option to output file which also set -dNOPAUSE and -dBATCH (see Interaction-related parameters)

Example:

$ du -h file.pdf 
27M file.pdf

$ gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -q -o output.pdf file.pdf

$ du -h output.pdf 
900K    output.pdf

Here -q suppress normal startup messages, and also do the equivalent of -dQUIET which suppresses routine information comments

Related Question