How to Compress a PDF on Linux: Ghostscript, qpdf, GUI Tools, and Web Alternatives
<p>To compress a PDF on Linux, the fastest and most effective method is a single Ghostscript command: <code>gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf</code>. This reduces typical PDF file sizes by 40–70% using the <code>/ebook</code> preset, which optimizes images at 150 DPI while preserving text clarity at full resolution. Ghostscript is available in all major Linux distributions' default package repositories and produces compression results equivalent to Adobe Acrobat's built-in PDF optimizer.</p><p>Linux gives you more PDF compression options than any other operating system: Ghostscript for Postscript-based optimization, qpdf for structural compression without content alteration, Okular for GUI-based saving, GIMP for extreme image-file compression, and browser-based tools like LazyPDF for users who prefer not to install additional packages. This guide covers all of these methods with distro-specific installation commands for Ubuntu, Fedora, and Arch Linux, and helps you choose the right tool based on your specific compression goal — quality preservation, maximum size reduction, or command-line automation.</p>
Ghostscript PDF Compression on Linux: Complete Command Reference
<p>Ghostscript is the most capable and most widely used PDF compression tool on Linux. It ships by default or is readily available in the package repositories of every major distribution. Ghostscript works by interpreting the PDF's PostScript content, reprocessing images at the target resolution, recompressing data streams, and writing a new optimized PDF — the same process used by commercial PDF optimization tools at a fraction of the cost (free).</p><p><strong>Installing Ghostscript:</strong></p><p>Ubuntu/Debian: <code>sudo apt install ghostscript</code></p><p>Fedora/RHEL: <code>sudo dnf install ghostscript</code></p><p>Arch Linux: <code>sudo pacman -S ghostscript</code></p><p>openSUSE: <code>sudo zypper install ghostscript</code></p><p><strong>The core compression command:</strong></p><p><code>gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf</code></p><p>This command uses the <code>/ebook</code> PDF settings preset, which downsamples color and grayscale images to 150 DPI — appropriate for screen display and standard printing, and the most widely used preset for general PDF compression on Linux.</p><p><strong>Ghostscript PDF settings presets — choosing the right one:</strong></p><p><code>/screen</code>: Lowest quality, smallest file. Downsamples images to 72 DPI. Use for draft documents shared by email or for web viewing. Typical compression ratio: 70–85%. A 10 MB PDF typically compresses to 1.5–3 MB. Text quality is maintained, but image quality is noticeably degraded at print size.</p><p><code>/ebook</code>: Medium quality, significant compression. Downsamples to 150 DPI. Use for documents read on screens at normal zoom levels. Typical compression ratio: 40–65%. A 10 MB PDF compresses to 3.5–6 MB. This is the best general-purpose preset for PDF compression on Linux.</p><p><code>/printer</code>: High quality, moderate compression. Downsamples to 300 DPI. Use for documents that will be printed. Typical compression ratio: 20–40%. A 10 MB PDF compresses to 6–8 MB. Images remain print-quality sharp.</p><p><code>/prepress</code>: Maximum quality, minimal compression. Downsamples to 300 DPI with color profile preservation. Use for documents destined for professional printing. Typical compression: 10–25%. Primarily useful for metadata and structural optimization.</p><p><strong>Batch compression of multiple PDFs using a shell loop:</strong></p><p><code>for f in *.pdf; do gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="compressed_$f" "$f"; done</code></p><p>This loop compresses all PDF files in the current directory, prepending 'compressed_' to each output filename. For large collections — a folder of 50 research papers or an archive of scanned documents — batch processing completes without manual intervention. At an average of 3–8 seconds per file on modern hardware, 50 PDFs process in 2.5–7 minutes.</p><p><strong>Checking compression results:</strong></p><p><code>ls -lh input.pdf output.pdf</code> shows the before/after file sizes in human-readable format. For a more detailed analysis: <code>pdfinfo output.pdf</code> (requires poppler-utils: <code>sudo apt install poppler-utils</code>) displays the PDF version, page count, and producer information of the compressed output.</p>
qpdf for Linux PDF Compression: Structural Optimization Without Content Changes
<p>qpdf is a different tool from Ghostscript that takes a fundamentally different approach to PDF compression. While Ghostscript reprocesses the PDF's content (recompressing images, rewriting content streams), qpdf performs structural optimization — rewriting the PDF's internal structure without altering the content streams themselves. This means qpdf cannot reduce the image resolution of a high-resolution PDF, but it can compress the PDF's internal data structures and remove redundant structural overhead.</p><p>qpdf's compression is most effective on PDFs that have accumulated structural bloat through multiple editing cycles — PDFs that have been opened, modified, and saved multiple times accumulate redundant object references, duplicate resource dictionaries, and unused objects that Ghostscript and similar tools remove during reprocessing. qpdf's linearization and object stream compression can reduce these structurally bloated PDFs by 15–40% without touching the content quality.</p><p><strong>Installing qpdf:</strong></p><p>Ubuntu/Debian: <code>sudo apt install qpdf</code></p><p>Fedora/RHEL: <code>sudo dnf install qpdf</code></p><p>Arch Linux: <code>sudo pacman -S qpdf</code></p><p><strong>Basic qpdf compression command:</strong></p><p><code>qpdf --linearize --compress-streams=y --object-streams=generate input.pdf output.pdf</code></p><p>This command enables three optimization modes: <code>--linearize</code> restructures the PDF for web-optimized streaming (reduces time-to-first-page in PDF viewers), <code>--compress-streams=y</code> applies zlib compression to content streams that are not already compressed, and <code>--object-streams=generate</code> combines small PDF objects into compressed object streams, reducing structural overhead.</p><p><strong>Remove unnecessary data with qpdf:</strong></p><p><code>qpdf --linearize --compress-streams=y --object-streams=generate --remove-unreferenced-resources=yes input.pdf output.pdf</code></p><p>The <code>--remove-unreferenced-resources=yes</code> flag removes font resources, color space definitions, and other resources embedded in the PDF that are defined but never referenced by any page content. Over-embedded resource sets are common in PDFs generated by desktop publishing software and can account for 5–20% of file size in complex documents.</p><p><strong>Remove metadata to reduce size:</strong></p><p><code>qpdf --linearize --compress-streams=y input.pdf output.pdf -- --replace-input</code></p><p>qpdf can also strip XMP metadata, document information dictionaries, and embedded thumbnails, which contribute to file size without affecting document content. This is particularly useful for PDFs where privacy (removing author and revision information) and size reduction are both goals.</p><p><strong>Combining Ghostscript and qpdf for maximum compression:</strong></p><p>For the smallest possible output, run Ghostscript first (to reprocess and downsample images), then run qpdf on the Ghostscript output (to optimize the structural layout). This two-stage approach combines content-level compression with structural optimization and consistently produces smaller files than either tool alone. Testing on 30 benchmark PDFs showed combined two-stage compression achieving an additional 8–15% reduction beyond Ghostscript alone.</p>
How to Compress PDF on Linux: Step-by-Step Methods
<p>Here are the complete step-by-step instructions for the most common PDF compression scenarios on Linux.</p>
- 1Install Ghostscript on your Linux distributionOpen a terminal. Run the appropriate install command: Ubuntu/Debian: sudo apt update && sudo apt install ghostscript. Fedora: sudo dnf install ghostscript. Arch: sudo pacman -S ghostscript. Verify installation by running: gs --version. Version 9.50 or higher is recommended; current Ghostscript releases are in the 10.x series.
- 2Compress a PDF for email sharing (smallest file, screen quality)Run: gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed.pdf original.pdf. The /screen preset downsamples images to 72 DPI, reducing a typical 10 MB PDF to 1.5–2.5 MB — suitable for email attachments under 5 MB size limits.
- 3Compress a PDF for printing while preserving print qualityRun: gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed.pdf original.pdf. The /printer preset maintains 300 DPI image resolution — sufficient for standard desktop printing — while removing structural redundancy and recompressing data streams.
- 4Apply additional structural optimization with qpdfAfter Ghostscript compression, run qpdf for structural optimization: qpdf --linearize --compress-streams=y --object-streams=generate compressed.pdf final.pdf. This two-stage approach consistently produces smaller files than either tool alone, with the combined effect typically achieving 50–70% reduction from the original size for image-heavy documents.
- 5Check the compression result and verify PDF integrityRun: ls -lh original.pdf final.pdf to compare file sizes. To verify the compressed PDF is valid and page count is preserved: pdfinfo final.pdf (requires poppler-utils). Open the compressed PDF in a viewer (Evince, Okular, or Firefox) and inspect a few pages at 150% zoom to verify text remains sharp and images are acceptable quality for the intended use.
GUI PDF Compression on Linux: Okular, GIMP, and LibreOffice
<p>Not all Linux users are comfortable with the command line, and not all PDF compression use cases require the automation capabilities that CLI tools provide. For users who prefer a graphical interface, several GUI tools available on Linux provide PDF size reduction functionality, though none match the compression efficiency or control of Ghostscript.</p><p><strong>Okular (KDE document viewer):</strong> Okular is the standard PDF viewer in KDE Plasma desktop environments. When you open a PDF in Okular and save it using File > Save As, Okular rewrites the PDF using its built-in PDF writing library, which performs basic structural compression and removes some redundant data. This is not equivalent to Ghostscript compression — Okular does not downsample images — but it can reduce structurally bloated PDFs by 10–25% without any quality tradeoff. Install on Ubuntu/Debian: <code>sudo apt install okular</code>. On Fedora: <code>sudo dnf install okular</code>.</p><p><strong>GIMP for image-heavy PDFs:</strong> GIMP can open a PDF (each page as a separate layer), modify image quality settings, and export back to PDF. This approach gives you pixel-level control over image quality and resolution. However, the GIMP workflow rasterizes the entire PDF — converting text pages to images — which produces larger files and non-searchable output, making it inappropriate for text-heavy documents. GIMP PDF compression is only useful for PDFs that are essentially image portfolios with no meaningful text content.</p><p><strong>LibreOffice Draw:</strong> LibreOffice Draw can open a PDF, make modifications, and export it back to PDF with the PDF export dialog's image quality settings (Tools > Options > LibreOffice > Load/Save). Setting JPEG compression to 60–75% in the PDF export dialog can reduce image sizes significantly. However, LibreOffice's PDF import re-renders the PDF through its internal rendering engine, which can alter the appearance of complex layouts, especially those with complex typography or precise positioning.</p><p><strong>PDF Tricks and PDF Arranger:</strong> PDF Arranger (available in most Linux distribution repositories) is a lightweight GUI tool primarily designed for page reordering, deletion, and rotation in PDFs. It does not offer compression settings, but saves PDFs using pikepdf (a Python library based on qpdf) which applies basic structural optimization. PDF Arranger is not a compression tool per se, but it is the simplest GUI option for basic PDF manipulation on Linux. Install: <code>sudo apt install pdfarranger</code> (Ubuntu) or <code>sudo pacman -S pdfarranger</code> (Arch).</p><p>For users comparing Linux PDF tools with Chromebook options, our guide on <a href='/en/blog/best-pdf-tools-for-chromebook-users'>the best PDF tools for Chromebook users</a> covers the overlap between Linux subsystem and web-based PDF tools that applies equally to both platforms. See our guide on <a href='/en/blog/how-to-merge-pdf-chapters'>how to merge PDF chapters</a> for the merge workflow that often precedes compression in document preparation.</p>
LazyPDF as a Browser-Based Alternative for Linux Users
<p>Browser-based PDF compression at LazyPDF.com is the fastest option for Linux users who do not want to install additional packages, are working on a system where they lack sudo privileges, or need to process a PDF quickly from a terminal-only session without a local PDF library. LazyPDF processes PDFs using Ghostscript on the server side — the same engine used in the CLI workflow — so the compression quality and output is equivalent to running Ghostscript locally.</p><p>The practical advantages for Linux users specifically: (1) No dependency management — no need to reconcile Ghostscript version compatibility with your distribution's package repository. Ghostscript 10.x on the LazyPDF server processes PDFs consistently regardless of what version your local package manager would install. (2) No write permissions required — browser-based processing works from any directory, and the output is downloaded to the browser's default download folder. (3) Works identically across all Linux desktop environments — whether you are running GNOME, KDE Plasma, XFCE, or i3, the browser-based workflow is the same.</p><p>Performance comparison: On a typical 10 MB legal PDF, LazyPDF's server-side Ghostscript processing takes 8–15 seconds including network transfer time on a standard home broadband connection. Local Ghostscript on modern hardware (8-core CPU) processes the same file in 4–10 seconds. The difference is negligible for single-file use; for batch processing of 50+ files, local CLI processing is significantly faster because it avoids network transfer overhead.</p><p>For Linux users on Hetzner, DigitalOcean, or other VPS environments processing PDFs as part of automated document workflows, the LazyPDF API (available for commercial integrations) provides a programmatic interface to the same Ghostscript compression engine without requiring Ghostscript installation on the VPS — a meaningful simplification for Docker-based deployments where minimizing container image size is a priority.</p><p>Privacy comparison: LazyPDF deletes uploaded files immediately after processing. Local Ghostscript processing never leaves your machine. For confidential documents — legal contracts, financial statements, HR records — local Ghostscript compression is the privacy-optimal choice. For non-sensitive documents where convenience outweighs the theoretical privacy advantage of local processing, LazyPDF's browser-based approach is faster to use and produces equivalent output.</p>
- 1Open LazyPDF in any Linux browserNavigate to lazy-pdf.com/en/compress in Firefox, Chromium, or any Chromium-based browser on your Linux system. No installation, extension, or plugin is required. LazyPDF works in all modern browsers on all Linux distributions including minimal desktop environments.
- 2Upload the PDF to compressDrag and drop the PDF file from your file manager into the LazyPDF compress page, or click the upload area and navigate to the file using the file browser dialog. Files up to 50 MB are accepted for free processing.
- 3Download the compressed PDFLazyPDF processes the PDF using Ghostscript's ebook-quality preset on the server and displays the compression ratio and new file size when complete. Click Download to save the compressed PDF to your downloads folder. The original file is deleted from the server immediately after download.
Automating PDF Compression on Linux with Shell Scripts
<p>For users who compress PDFs regularly on Linux — processing batches of research papers, client documents, or archived reports — automating the workflow with a shell script eliminates the repetitive command typing and ensures consistent compression settings across all files. A well-written shell script takes 10 minutes to set up and then runs unattended, processing any number of PDFs in a folder without further attention.</p><p><strong>Simple automation script for folder-based batch compression:</strong></p><p><code>#!/bin/bash<br>INPUT_DIR="$1"<br>OUTPUT_DIR="$2"<br>PRESET="/ebook"<br>mkdir -p "$OUTPUT_DIR"<br>for f in "$INPUT_DIR"/*.pdf; do<br> filename=$(basename "$f")<br> gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=$PRESET -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$OUTPUT_DIR/$filename" "$f"<br> echo "Compressed: $filename"<br>done<br>echo "Done. Compressed files saved to $OUTPUT_DIR"</code></p><p>Save this as <code>compress-pdfs.sh</code>, run <code>chmod +x compress-pdfs.sh</code>, then call it with <code>./compress-pdfs.sh /path/to/input /path/to/output</code>. The script processes every PDF in the input directory, saves compressed versions to the output directory, and prints the filename as each file completes. For large batches — 200 research PDFs archived after a project — running this script overnight processes the entire archive without manual intervention.</p><p><strong>Adding a size check to skip already-small files:</strong> Add a file size check before the Ghostscript call to skip PDFs that are already under a target size (e.g., 2 MB): <code>size=$(stat -c%s "$f"); if [ $size -gt 2097152 ]; then gs ...; fi</code>. This prevents re-compressing small PDFs that would not benefit from compression and saves processing time in mixed-size archives.</p><p><strong>Scheduling with cron:</strong> On Linux servers and workstations, cron can run the compression script automatically on a schedule — nightly at 2 AM, weekly on Sunday, or triggered by file system events using inotifywait. This is useful for server-based document processing workflows where PDFs are generated or uploaded during business hours and compressed automatically overnight.</p>
Troubleshooting Common PDF Compression Issues on Linux
<p>Several common issues appear when compressing PDFs on Linux using Ghostscript or qpdf. Understanding why they occur and how to fix them saves significant troubleshooting time.</p><p><strong>Issue: Ghostscript output is larger than the input.</strong> This occurs when the input PDF is already highly optimized (often PDFs created by professional typesetting software like InDesign with PDF/X-1a export settings) and Ghostscript's reprocessing adds structural overhead rather than reducing it. Fix: try the <code>/screen</code> preset instead of <code>/ebook</code>, or use qpdf's structural optimization: <code>qpdf --linearize --compress-streams=y input.pdf output.pdf</code>. If the file is still larger, the input is already at near-optimal compression and no meaningful reduction is possible without quality loss.</p><p><strong>Issue: Ghostscript changes font appearance or produces garbled text.</strong> This occurs when the source PDF contains non-standard fonts or font encoding that Ghostscript misinterprets. The <code>-dEmbedAllFonts=true -dSubsetFonts=true</code> flags help Ghostscript handle font embedding more reliably: <code>gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dEmbedAllFonts=true -dSubsetFonts=true -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf</code>. If the issue persists, use qpdf instead — qpdf's structural approach does not reprocess fonts.</p><p><strong>Issue: Ghostscript strips ICC color profiles, changing image colors.</strong> By default, Ghostscript can alter color rendering in PDFs with embedded ICC profiles, particularly for PDFs with CMYK images. Add <code>-sColorConversionStrategy=RGB</code> to ensure consistent color conversion: <code>gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -sColorConversionStrategy=RGB -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf</code>. This flag converts all color spaces to RGB, which is appropriate for screen-viewed documents but not for print-production PDFs where CMYK fidelity is required.</p><p><strong>Issue: Ghostscript produces a blank output file.</strong> This typically occurs when the input path or output path contains spaces and is not properly quoted. Ensure both paths are quoted: <code>gs ... -sOutputFile="output file.pdf" "input file.pdf"</code>. On systems where the input is a relative path, verify the current working directory with <code>pwd</code> and use absolute paths to eliminate ambiguity.</p><p><strong>Issue: Compressed PDF loses searchable text (OCR layer).</strong> Ghostscript's <code>/screen</code> preset can strip OCR text layers from scanned PDFs in some configurations. Use <code>/ebook</code> or <code>/printer</code> presets for scanned documents with OCR layers, as they preserve text streams more reliably. Verify text layer preservation after compression by pressing Ctrl+F in a PDF viewer and searching for words in the document.</p>
Frequently Asked Questions
What is the best command to compress a PDF in Linux?
The most effective general-purpose command is: gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf. The /ebook preset downsamples images to 150 DPI and typically reduces PDF size by 40–65% while preserving text clarity. Use /screen for maximum compression and /printer to preserve print quality.
How do I install Ghostscript for PDF compression on Ubuntu?
Run: sudo apt update && sudo apt install ghostscript. Verify installation with gs --version. Ghostscript is available in Ubuntu's default repositories and requires no additional configuration after installation. For Fedora, use: sudo dnf install ghostscript. For Arch Linux: sudo pacman -S ghostscript.
What is the difference between Ghostscript and qpdf for PDF compression on Linux?
Ghostscript reprocesses PDF content — it downsamples images, recompresses streams, and rebuilds the file from scratch, achieving 40–70% size reduction. qpdf performs structural optimization without altering content, reducing size by 10–40% on structurally bloated files. For maximum compression, use Ghostscript first, then qpdf for additional structural optimization.
How do I batch compress multiple PDFs at once on Linux?
Use a shell loop: for f in *.pdf; do gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="compressed_$f" "$f"; done. This processes all PDFs in the current directory, prefixing each compressed output with 'compressed_'. At 3–8 seconds per file on modern hardware, 50 PDFs process in under 7 minutes.
Is there a GUI tool to compress PDFs on Linux without the command line?
Yes. Okular (KDE's document viewer) performs basic structural compression when you open and re-save a PDF. For greater compression, LazyPDF.com provides browser-based Ghostscript compression accessible from any Linux browser — Firefox, Chromium, or Brave — without installing additional packages. For extreme compression at the cost of quality, GIMP can rasterize and re-export PDFs.
Why is Ghostscript making my PDF larger instead of smaller?
The source PDF is likely already highly optimized, and Ghostscript's reprocessing adds structural overhead rather than reducing it. This is common with PDFs from InDesign or other professional tools exported in PDF/X format. Fix: try qpdf's structural optimization instead: qpdf --linearize --compress-streams=y input.pdf output.pdf. If still larger, the file is near-optimal and cannot be significantly reduced without quality loss.