Compress PDF files on Linux

pdfThe major benefit of PDF documents is the intended representation remains almost same on any operating system or device. However, scanned PDFs can be of large sizes and you may need to optimize or reduce the size of the file to share it with a friend. This article discusses several ways to do that on Linux with near-original quality.

Native solutions

  • Ghostscript is a great tool for compressing PDFs. In our tests it delivered the best compression ratio. Simply run:
    $ gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf in.pdf

    -dPDFSETTINGS can be any of:
    /screen : low-resolution output, lowest output size
    /ebook : medium-resolution output, medium output size
    /printer OR /prepress : high-resolution with maximum output size

  • Run the Shrinkpdf script:
    $ ./shrinkpdf in.pdf out.pdf

    The script is almost same as the explicit gs command above. However, it has one advantage – it does an output file size check.

  • qpdf:  A cmdline program that does structural, content-preserving changes to PDF files. The simplest way to invoke it:
    $ qpdf --linearize input.pdf output.pdf

    However, this didn’t provide a very optimized output in our tests.
    To install qpdf on Ubuntu, run:

    $ sudo apt-get install qpdf
  • smpdf is a commercial closed source tool. However, there is an evaluation copy available for download which adds an unlicensed version mark to the modified document. Usage:
    $ smpdf in.pdf -o out.pdf

5 thoughts on “Compress PDF files on Linux”

  1. If you are only going to open it on Linux, at the very least evince can transparently open any of the common single-file compressed formats. For example, most of my collection is in pdf.xz. The specific advantage here is that it is loseless.

Leave a Reply

Your email address will not be published. Required fields are marked *