PDF300

How to Compress a PDF on Linux (Ghostscript, qpdf, a GUI, and When to Use a Target-Size Tool)

Updated · 5 min read · By

The situation

You exported a PDF on Linux and it came out much larger than you expected. Maybe it is a scanned document, a report with charts, or a slide deck you need to attach. Now an upload form rejects it, or a mail server bounces the attachment for being too big.

The good news is that Linux already has everything you need to shrink a PDF, usually without installing anything. Most desktops ship with Ghostscript, and a single command does the heavy lifting. The catch is choosing the right setting, and knowing when a command that only guesses at the size is the wrong tool for a hard limit.

Why Linux PDFs get big

Almost every oversized PDF is heavy for one reason: images. A PDF is a container, and when it holds full-resolution photos or high-DPI scans, the file carries every one of those pixels. A single color page scanned at 600 DPI can be several megabytes on its own, no matter which operating system made it.

Text-only PDFs stay small because text is stored as compact drawing instructions, not pixels. So when a file is surprisingly large, the weight is almost always image data, sometimes embedded fonts or leftover high-resolution graphics, not the words on the page. That is why downsampling images is where real savings come from.

Method 1: Ghostscript, the standard command-line route

Ghostscript (gs) is the tool most Linux PDF compression relies on. On Debian or Ubuntu you can confirm or install it with sudo apt install ghostscript; Fedora uses sudo dnf install ghostscript. Then run:

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

The one setting that matters most is -dPDFSETTINGS. It controls how far images are downsampled:

PresetImage targetBest for
/screen~72 DPISmallest file, on-screen viewing only
/ebook~150 DPIThe usual sweet spot for email and uploads
/printer~300 DPIFiles that still need to print cleanly
/prepress~300 DPI, color-preservingKeeps the most quality, saves the least

Start with /ebook. If the result is still too big, step down to /screen; if images look too soft, step up to /printer. Always write to a new filename, as the command above does, so your original is never overwritten. The weakness of this route is that you cannot ask it for an exact size. You pick a preset, check the result, and try another if it missed.

Method 2: qpdf for lossless cleanup

Sometimes a PDF is bloated by its structure rather than its images: uncompressed object streams, duplicated resources, or leftover revision data. Ghostscript may not help much there, but qpdf can, without touching image quality at all. Install it with sudo apt install qpdf, then run:

qpdf --linearize --object-streams=generate input.pdf output.pdf

This rewrites the file more efficiently and is completely lossless, so text and images are untouched. The savings are modest on an already-tidy file but can be real on PDFs that software exported carelessly. A practical habit is to run qpdf first for a free, safe reduction, and only reach for Ghostscript if the file is still too large because of photos or scans.

Method 3: A GUI route, no terminal needed

If you would rather not open a terminal, two desktop options work on most distros. LibreOffice Draw can open a PDF, and under File then Export as PDF you can lower the image resolution and JPEG quality before re-exporting. Alternatively, many PDF viewers such as Okular let you Print to File and choose a lower output quality, which re-renders the document into a smaller PDF. Both are blunter than Ghostscript, but they avoid the command line entirely.

When to use a target-size tool instead

Every method above answers "make it smaller." None of them answers "make it fit under 10 MB." When a portal, a court, or an email rule hands you an exact ceiling, re-running Ghostscript with different presets until one lands is slow guesswork.

A target-size tool flips the logic: you state the size you need and it works backward to reach it. PDF300 lets you type a target file size and compresses the PDF to fit, and it runs in any Linux browser, so there is nothing to install or configure. It also offers an in-browser mode that re-encodes the file locally, so a private document never leaves your machine. For a stubborn file against a hard limit, that is faster than another round of presets. You can try it at PDF300.

Checklist

FAQ

Which Ghostscript setting should I use to compress a PDF on Linux?

Start with -dPDFSETTINGS=/ebook, which targets roughly 150 DPI images and usually keeps text and screen viewing sharp. Use /screen (72 DPI) only when you need the smallest possible file and can accept softer images, and /printer (300 DPI) when the PDF must still print cleanly. Always compare the output to the original before you send it.

Why did Ghostscript barely shrink my PDF?

Ghostscript mostly saves space by downsampling images. If your PDF is already low-resolution, or it is large because of embedded fonts or vector graphics rather than photos, there is little image data to remove. In that case qpdf can strip structural waste, but the file may simply be as small as it reasonably gets.

Can I compress a PDF on Linux without installing anything?

Yes. Most desktops already ship Ghostscript, so the command line needs no install. If you would rather not touch a terminal, a browser-based tool works on any Linux distro. PDF300 offers an in-browser mode that re-encodes the file locally, so it never leaves your machine.

Written by LeDeuxions, an architect who built PDF300 after a 300 MB portal limit kept rejecting drawing sets. Figures quoted from third parties link to their source; sizes and reductions described as "typical" are estimates, not guarantees.