Compressing PDFs using Ghostscript under Linux

I had to email a PDF with several high-resolution images embedded. The original file size was 7.31 MB and this was unnecessary large for a single page PDF. I did not need the very high-resolution of the pictures, but only that the PDF would look good on-screen and in print on a normal inkjet printer.

The magic of Ghostscript
Googling the terms “compressing pdf” revealed several online options for uploading and compressing PDFs, but since I was sitting in front of a Linux computer and didn’t really trust any of these unknown providers I ended up using Ghostscript instead. The following command compressed my PDF from 7.31MB to 674KB in about a second:

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

From the Ghostscript manual it can be seen that there are several qualities to choose from:

  • /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.

I tried them all and ended up with the “/printer” quality. Below is a list of the file sizes and my comments:

  • 77KB – output-screen.pdf – I didn’t like this setting, JPEG compression artifacts was very visible and the quality very low.
  • 167KB – output-ebook.pdf – Decent result, but compression clearly visible when zooming a bit.
  • 674KB – output-printer.pdf – Very good result, even when zoomed it looks respectable.
  • 986KB – output-prepress.pdf – Very good indeed, no visible artifacts when zoomed.
  • 373KB – output-default.pdf – Surprisingly not as good as expected with clear artifacts when zoomed.


This entry was posted in Articles, Computer. Bookmark the permalink.

6 Responses to Compressing PDFs using Ghostscript under Linux

  1. NPM says:

    just what I was looking for, I was compressing it with /screen but the graphics didn’t look good

  2. Mtgxyz says:

    Cool, this is exact that what I need!
    /screen is cool for Books with low-Res Images
    /ebook is good for Texts
    /printer is for the Normal Ink-Jet perfect
    /prepress is for photos

  3. Pingback: Compresser un fichier PDF sans (trop de) perte de qualité en ligne de commande

  4. Praveen Ravipati says:

    Thomas Jansson,

    could please share your comments on

  5. Ian Maxon says:

    Great stuff, thanks for writing this up.
    In my case, another variable to the size/quality tradeoff was the image resolution in DPI (-dColorImageResolution). Originally I had it set to 72 which is pretty aggressive, and even /prepress in that case is full of artifacts. Upping to 150 gave great results while still being way smaller than XSane’s uncompressed output.

Leave a Reply