Skip to main contentSkip to navigation
[email protected]
Client AreaSupport
Hosting Mammoth
HostingMammothYour Data, Our Responsibility
Home
Solutions
Hosting Services
Store
Pricing
About
Blog
API
Contact

Stay Ahead of the Curve

Get the latest insights on cybersecurity, AI innovations, and enterprise data solutions delivered to your inbox.

Hosting Mammoth
HostingMammothEnterprise Solutions

Enterprise-grade data solutions. Hosting, recovery, cybersecurity, and AI-powered services for businesses worldwide.

[email protected]
Sun - Fri, 9:00am - 5:00pm

Services

  • Cloud Hosting
  • Data Recovery
  • Cybersecurity
  • Legal Support
  • MSP Services
  • Web Development
  • AI Services
  • Free Server Migration

Hosting

  • VPS Hosting (NVMe SSD)
  • VDS Hosting (NVMe)
  • Storage VPS (High SSD)
  • GPU Servers
  • Managed Services
  • Cloud Firewall
  • Load Balancer
  • One-Click Apps
  • n8n Hosting
  • Object Storage
  • FAQ

Company

  • Store
  • Pricing
  • About Us
  • Locations
  • Blog
  • Testimonials
  • Contact
  • Affiliate Program
  • White-Label
  • Terms of Service
  • Privacy Policy
  • Browser Cookies
  • SLA

Support

  • Client Area
  • Submit Ticket
  • Knowledge Base
  • Server Status
  • API Documentation

© 2026 Hosting Mammoth. All rights reserved.

← Back to Blog
hostingApril 7, 20265 min read

Reduce PDF File Size in Linux: Tools and Methods

Learn how to reduce PDF file size in Linux using Ghostscript, ImageMagick, and cpdf. Practical methods for DevOps, automation, and desktop use.

A

Aisha Nkemdi

April 7, 2026

Reduce PDF File Size in Linux: Tools and Methods

Why PDF Compression Matters on Linux Systems

In this article, we explore reduce PDF file size Linux — Large PDF files create real operational friction — they breach email attachment limits, slow down file transfers to remote servers, and consume disproportionate storage on shared infrastructure. If you're managing document workflows on Linux, knowing cloud server solutions how to reduce PDF file size efficiently is a practical skill that pays dividends across DevOps pipelines, automated reporting systems, and everyday desktop use.

This guide covers the most reliable methods for PDF compression on Linux: Ghostscript for mixed-content documents, ImageMagick for image-heavy files, cpdf for lossless structural cleanup, and GUI options for one-off desktop jobs. Each method is matched to a specific use case so you can pick the right tool rather than defaulting to the first command you find. If you're running these workflows on a remote server, a solid VPS hosting environment gives you the compute headroom to process large document batches without timeout issues.

Understanding What Makes PDFs Large

Before reaching for a compression tool, diagnose the source of the bloat. Blindly running a compression command on an already-optimized PDF can actually increase file size — and that's wasted effort.

Start with two diagnostic commands:

Consider a professional security assessment from CyberXper to identify vulnerabilities in your infrastructure.

## Check file size
du -sh input.pdf

## Get PDF metadata and optimization status
pdfinfo input.pdf

Sample pdfinfo output:

Title:           Q3 Financial Report
Pages:           58
Page size:       595.28 x 841.89 pts (A4)
File size:       84231680 bytes
Optimized:       no
PDF version:     1.6

The Optimized: no flag is a strong signal that significant savings are available. Now install poppler-utils to inspect embedded images:

## Debian/Ubuntu
sudo apt install poppler-utils

## Fedora
sudo dnf install poppler-utils

## Arch Linux
sudo pacman -S poppler

## openSUSE
sudo zypper install poppler-tools

Then audit embedded image resolutions:

pdfimages -list input.pdf
page   num  type   width height color comp bpc  enc
---------------------------------------------------
   1     0 image    2480  3508  rgb     3   8  jpeg
   2     1 image    2480  3508  rgb     3   8  jpeg

Root Causes Checklist

  • High-resolution embedded images: Print-quality images at 300+ DPI in a document intended for screen reading. This is the most common cause of bloat.
  • Scanned document pages: Each page is a full raster bitmap. No text layer exists, so font compression offers zero benefit — DPI reduction is your primary lever.
  • Font and metadata overhead: Duplicate font streams from PDF merges, unused ICC color profiles, verbose XMP metadata blocks, and stale object references from incremental edits. These are invisible to readers but contribute meaningfully to file size.

Matching your compression method to the root cause is what separates a 70% size reduction from a 5% one.

Method 1: Ghostscript — The Recommended General-Purpose Approach

Ghostscript is the gold standard for PDF compression on Linux. It rewrites the PDF from scratch, resamples images to your target DPI, strips structural overhead, and produces consistent, repeatable output. It handles mixed text-and-image documents better than any other CLI tool.

Installation

## Debian/Ubuntu/Linux Mint
sudo apt install ghostscript

## Fedora
sudo dnf install ghostscript

## Arch Linux
sudo pacman -S ghostscript

## openSUSE
sudo zypper install ghostscript

## Verify installation
gs --version

The Core Compression Command

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

Flag breakdown:

  • -sDEVICE=pdfwrite — selects the PDF output renderer
  • -dCompatibilityLevel=1.4 — targets PDF 1.4 for maximum reader compatibility
  • -dPDFSETTINGS=/ebook — applies the ebook preset (150 DPI, best general-purpose balance)
  • -dNOPAUSE — disables per-page pause prompts
  • -dQUIET — suppresses informational stdout noise
  • -dBATCH — exits automatically after processing
  • -sOutputFile=output.pdf — output path (never point this at your input file)

Critical: Never set -sOutputFile to the same path as input.pdf. Ghostscript reads and writes simultaneously — overwriting the source produces a zero-byte or corrupted output file.

Choosing the Right -dPDFSETTINGS Preset

Preset DPI Typical Reduction Best For
/screen 72 70–85% Email previews, web thumbnails
/ebook 150 40–60% General sharing, email attachments
/printer 300 10–30% Desktop printing, internal docs
/prepress 300 5–15% Commercial print, color-accurate output
/default varies Minimal May increase size on optimized PDFs

For most use cases — sharing reports, sending invoices, distributing documentation — /ebook is the right default. If the output looks degraded at normal zoom, step up to /printer.

Real-World Compression Example

## Before
ls -lh input.pdf
## -rw-r--r-- 1 user user 73M Jan 10 09:00 input.pdf

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

## After
ls -lh output.pdf
## -rw-r--r-- 1 user user 14M Jan 10 09:01 output.pdf

A 73 MB source file becomes 14 MB — an 81% reduction. Always open the output and visually verify text readability and image quality before discarding the original.

Batch Compression with a Shell Loop

For processing multiple PDFs in a directory, use a loop that writes output to a separate folder:

mkdir -p compressed

for f in *.pdf; do
  gs \
    -sDEVICE=pdfwrite \
    -dCompatibilityLevel=1.4 \
    -dPDFSETTINGS=/ebook \
    -dNOPAUSE -dQUIET -dBATCH \
    -sOutputFile="compressed/${f}" \
    "$f"
done

This is particularly useful in automated document processing pipelines. If you're building this into a CI/CD workflow or scheduled job, see Read more about this topic for integration patterns.

Method 2: ps2pdf — A Faster One-Liner Wrapper

ps2pdf is a thin wrapper around Ghostscript that accepts the same -dPDFSETTINGS flags with less typing. It's part of the ghostscript package, so no separate installation is needed.

ps2pdf \
  -dPDFSETTINGS=/ebook \
  input.pdf \
  output.pdf

Under the hood, this invokes the same Ghostscript engine as Method 1. Use it when you want a quick one-liner and don't need fine-grained flag control. The output quality and file size will be identical to the equivalent gs command.

Method 3: ImageMagick — Best for Image-Only PDFs

When your PDF consists entirely of scanned pages or photographic images — no selectable text, no vector elements — ImageMagick's convert command gives you direct control over DPI and JPEG quality.

Installation

## Debian/Ubuntu
sudo apt install imagemagick

## Fedora
sudo dnf install ImageMagick

## Arch Linux
sudo pacman -S imagemagick

Fix the Policy File First (Debian/Ubuntu)

On Debian-derived systems, ImageMagick ships with PDF read/write rights disabled in its security policy. You'll get a not authorized error without this fix:

sudo nano /etc/ImageMagick-6/policy.xml

Find the line:

<policy domain="coder" rights="none" pattern="PDF" />

Change rights="none" to rights="read|write":

<policy domain="coder" rights="read|write" pattern="PDF" />

Save and close. Revert this change after use if you're on a shared or production system — it's a security restriction for good reason.

Compress a Scanned PDF

convert \
  -density 150 \
  -compress jpeg \
  -quality 75 \
  input.pdf \
  output.pdf
  • -density 150 — sets the output resolution to 150 DPI
  • -compress jpeg — uses JPEG compression for image pages
  • -quality 75 — JPEG quality (70–80 is a good range for scanned text documents)

For black-and-white scanned text, adding -colorspace Gray can cut file size further:

convert \
  -density 150 \
  -colorspace Gray \
  -compress jpeg \
  -quality 75 \
  input.pdf \
  output.pdf

Note: ImageMagick is not suitable for PDFs with selectable text or vector graphics. It rasterizes everything, which can degrade text sharpness. Use Ghostscript for mixed-content documents.

Method 4: cpdf — Lossless Structural Cleanup

If your PDF is already image-optimized but still larger than expected, the bloat is likely structural: redundant objects, duplicate font streams, stale cross-reference tables, or verbose metadata. cpdf -squeeze performs a lossless cleanup pass — no pixels are resampled, no content is altered.

Installation

Download the appropriate binary from the cpdf GitHub releases page and place it in your $PATH:

chmod +x cpdf
sudo mv cpdf /usr/local/bin/

Run a Squeeze Pass

cpdf -squeeze input.pdf -o output.pdf

This is safe to run on any PDF — it will never increase file size and never degrades quality. Use it as a final cleanup step after Ghostscript compression, or as a standalone pass when you need size reduction without any quality trade-off.

Method 5: GUI Options — LibreOffice Draw and PDF Arranger

For one-off compression tasks where scripting adds no value, two desktop tools cover the most common scenarios:

LibreOffice Draw can open a PDF, then export it with compression settings via File > Export as PDF. Under the Images tab, reduce the DPI and enable JPEG compression. This is effective for mixed-content PDFs and requires no terminal access.

PDF Arranger is a lightweight GTK application for reordering, deleting, and re-exporting PDF pages. It's particularly useful for trimming unnecessary pages before compression:

## Debian/Ubuntu
sudo apt install pdfarranger

For teams managing document workflows at scale, a managed IT services provider can help automate these compression pipelines and integrate them with your existing document management systems.

Choosing the Right Method: Decision Guide

Scenario Recommended Tool
Mixed text and images, general sharing Ghostscript /ebook
Scanned pages, no text layer ImageMagick with -density 150
Already image-optimized, still large cpdf -squeeze
Quick one-liner, same quality as gs ps2pdf
One-off desktop job, no terminal LibreOffice Draw or PDF Arranger
Batch processing in a pipeline Ghostscript shell loop

Conclusion: Reduce PDF File Size in Linux the Right Way

Reducing PDF file size in Linux is not a one-size-fits-all operation. The right approach depends on what's causing the bloat — high-resolution images, scanned raster pages, or structural overhead from incremental edits and merges. Ghostscript with the /ebook preset handles the majority of real-world cases and should be your first tool. For image-only scans, ImageMagick gives you direct control over DPI and quality. For lossless cleanup, cpdf -squeeze is safe, fast, and reliable.

Always verify results with ls -lh or du -sh before and after, and open the compressed output to confirm visual quality meets your requirements. For more Linux file management techniques, explore Read more about this topic and related article. Additional tools and resources for Linux-based document processing are available at Data Mammoth.

#hosting

Related Services

VPS Hosting →

Deploy on high-performance SSD servers

View Plans →

Cloud VPS plans from $4.99/mo

Share this article

Twitter / XLinkedInFacebook

Related Articles

hosting

The Compliance Gap in AI-Native Infrastructure: SOC2 and Data Residency for GPU Workloads

5 min read
hosting

Running OpenBao on Kubernetes with a CloudNativePG PostgreSQL backend

5 min read
hosting

Kubernetes v1.37: Hardening Container Storage with Bind Mount Options and EmptyDir Permissions

5 min read