A Lazy Developer's Guide to Reducing PDF Size

Engineering Jul 27, 2020

Sometimes you receive PDFs which are too large in size. It could be because the PDF contains images, or it is created by scanning physical pages. There are several ways to reduce the PDF size -

  1. Use Adobe Acrobat's Compress PDF function,
  2. Use one of many online tools,
  3. Export PDF as lower quality JPEG, and then export JPEG as PDF...phew
  4. On Mac OS, use Preview's "Reduce File Size" filter - this doesn't always work - sometimes the output PDF is larger than input.

I sometimes receive PDFs which I need to reduce below 250 KB to upload in my storage. My way of doing this is to use ghostscript.

ghostscript can be downloaded/installed from here for Windows and Linux, while on Mac OS:

brew install ghostscript

To reduce the PDF size, open Terminal/Console, and run:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=<OUTPUT PDF> <INPUT PDF>

The magic happens in PDFSETTINGS, for which the documentation for is available here. To summarize

  • -dPDFSETTINGS=/screen lower quality, smaller size (72 dpi)
  • -dPDFSETTINGS=/ebook better quality, larger size (150 dpi)
  • -dPDFSETTINGS=/prepress same as Acrobat Distiller "Prepress Optimized" setting (300 dpi)
  • -dPDFSETTINGS=/printer same as Acrobat Distiller "Print Optimized" setting (300 dpi)
  • -dPDFSETTINGS=/default useful across a wide variety of uses, which may result in a larger output file

(More Lazy Developer's Guides)

Brajesh Sachan

Brajesh drives direction of Deskera’s future technology and shapes Deskera as the technology leader.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.