I needed to shrink a PDF last week — something I don’t do often enough to remember the flags. Ghostscript is the tool, and it’s already on most Linux machines or a quick apt install ghostscript away.

The command is:

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

The bit that actually matters is -dPDFSETTINGS=/screen. That’s the quality dial. /screen gives you the smallest file — fine for emailing or uploading, rubbish if you need to print anything.

There are four other options worth knowing about:

  • /screen — lowest quality, smallest file. Good for on-screen viewing.
  • /ebook — better quality, still compressed. My default when I actually care about how it looks.
  • /printer — high quality, suitable for printing. File size jumps noticeably.
  • /prepress — highest quality, largest file. Overkill unless you’re sending to a print shop.

I usually start with /ebook and check the output. If it’s still too big I drop to /screen. If it looks muddy I go up to /printer.

The other flags are just boilerplate: -dNOPAUSE -dQUIET -dBATCH keeps it running without prompting, and -sCompatibilityLevel=1.4 makes sure the output is widely readable. Older PDFs sometimes need that lower compatibility level to avoid issues with certain viewers.

It’s not the most elegant solution — Ghostscript’s output can look a bit soft compared to the original — but it’s fast, it’s scriptable, and it works. I’ve been using it for years and haven’t found anything better that doesn’t involve a GUI tool or an online service.