Skip to main content
image&pdf.com
Home/Blog/qpdf vs Ghostscript vs pikepdf for PDF Compression — Real-World Benchmark (2026)
PDF ToolsJune 23, 20269 min read

qpdf vs Ghostscript vs pikepdf for PDF Compression — Real-World Benchmark (2026)

Three libraries, three real PDFs, head-to-head numbers. When each one wins, where each one loses, and which one we actually ship in production.

Kummari Achyuth

By Kummari Achyuth

Published June 23, 2026 · Reviewed by the Achyuth editorial process

Reviewed
Each tool linked here shows its privacy mode on the upload areaFree, no sign-upWorks on any device

Quick Answer

qpdf (and its Python binding pikepdf) repacks the PDF container without touching content — lossless, preserves signatures, 20-60% smaller on text-heavy PDFs. Ghostscript aggressively downsamples embedded images — 60-90% smaller on photo-heavy PDFs but visibly degrades image quality and breaks digital signatures. Pick qpdf/pikepdf as the default; switch to Ghostscript only when you need maximum size reduction on a scanned or photo-heavy PDF and don't care about visible quality loss.

The three libraries

qpdfis a C++ command-line tool and C++ library, first released in 2008, maintained by Jay Berkenbilt. It's the de-facto reference implementation for PDF transformations that don't involve rendering — repacking, linearization, encryption, decryption, page-level operations. Available on every major OS via package manager. The compression approach: rewrite the PDF's object stream packing and recompress existing flate streams at maximum effort. Never touches image data.

pikepdf is the Python binding for qpdf, maintained by James R. Barlow. Same underlying engine — same compression behaviour, same correctness guarantees, same speed. The difference is the API: you work with Python objects (pdf = pikepdf.open('input.pdf'); pdf.save('out.pdf')) instead of shelling out. For any Python pipeline, pikepdf is the natural choice. Output is byte-equivalent to qpdf's output for the same options.

Ghostscript is a much older PostScript and PDF interpreter, first released in 1988, maintained by Artifex. Its compression mode (-sDEVICE=pdfwrite with preset profiles like /screen, /ebook, /printer, /prepress) takes a fundamentally different approach: it re-rasterises the PDF through its internal renderer, then writes a new PDF from the rasterised representation. Image data is downsampled and re-compressed. This is what makes it both powerful (big savings on scans) and dangerous (always lossy for images, breaks signatures, occasionally breaks text rendering on PDFs with unusual font encodings).

The test corpus

Three real PDFs from our internal test set, each chosen to stress a different compression behaviour:

  1. Text contract — 12 pages, two columns, embedded Helvetica + a few Symbol glyphs, no images. A typical legal contract from a US enterprise law firm. Source size: 247 KB.
  2. Scanned bank statement — 5 pages, image-only (each page is a 300 DPI scan stored as embedded JPEG inside the PDF), no text layer. From a US retail bank monthly statement. Source size: 8.4 MB.
  3. Photo-heavy brochure — 2 pages, real-estate marketing flyer with 8 high-resolution photos (each photo embedded as a 2400×1600 JPEG) plus text. Source size: 32.1 MB.

For each PDF I ran each library at its "recommended default" setting:

  • qpdf: qpdf --linearize --object-streams=generate --recompress-flate --compression-level=9 input.pdf output.pdf
  • pikepdf: pdf = pikepdf.open('input.pdf'); pdf.save('output.pdf', object_stream_mode=pikepdf.ObjectStreamMode.generate, compress_streams=True, stream_decode_level=pikepdf.StreamDecodeLevel.generalized)
  • Ghostscript: gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -sOutputFile=output.pdf input.pdf

Results

PDFSourceqpdfpikepdfGhostscript (/ebook)
12-page text contract247 KB112 KB (-55%)112 KB (-55%)108 KB (-56%)
5-page scanned bank statement8.4 MB7.9 MB (-6%)7.9 MB (-6%)1.2 MB (-86%)
2-page real-estate brochure32.1 MB29.8 MB (-7%)29.8 MB (-7%)4.6 MB (-86%)

How to read the numbers

Text contract:all three libraries produce nearly-identical output (~55% smaller). For text-heavy PDFs, the savings come from the same source — repacking the cross-reference table, packing objects into object streams, recompressing flate streams. Ghostscript's extra 1% comes from font sub-setting it does as part of its re-render pass.

Scanned bank statement and brochure: qpdf and pikepdf barely move the needle (6-7%) because the embedded JPEGs are already optimally compressed and they refuse to touch image data. Ghostscript hammers it down by 86% because it downsamples each embedded image from ~300 DPI to ~150 DPI and re-encodes at ~75% JPEG quality. The size difference between source and Ghostscript output is overwhelmingly the image data being downscaled, not the PDF container being optimised.

Crucially: the Ghostscript output is visibly different from the source. Zoom into the bank statement at 200% and you can see JPEG ringing artefacts around the printed text. Zoom into the brochure photos and skin tones look slightly muddier. For pure size, Ghostscript wins. For visual fidelity, qpdf/pikepdf win.

Quality and feature trade-offs

Propertyqpdf / pikepdfGhostscript
Visual quality preservedBit-identicalLossy on images
Digital signatures preservedYesInvalidated
Form fields preservedYesUsually flattened
Text always selectableYesMostly — fails on unusual font encodings
Best on text-heavy PDFsYes (~55% savings)Tied (~56%)
Best on image-heavy PDFsWeak (~6%)Strong (~86%)
Speed (12-page text contract)~120 ms~800 ms
Speed (32 MB brochure)~400 ms~7 s

Which one we ship in production

Our PDF compress tool uses pikepdf. Three reasons:

  1. Lossless is the right default. Most users uploading a PDF expect the output to look identical to the input. A tool that silently degrades image quality to chase a smaller file size is doing the wrong thing for the majority case.
  2. Signature preservation matters.A meaningful fraction of compressed PDFs are signed contracts. Ghostscript would invalidate them; pikepdf doesn't.
  3. Speed matters for a web tool.120 ms vs 800 ms on a small file isn't visible to a human, but 400 ms vs 7 seconds on a big file is the difference between "feels instant" and "is the page broken?".

For the explicit "I need this file under 100 KB no matter what" use case, we run Ghostscript with the /screen preset behind the Compress PDF to 100 KB tool. The trade-off is explicit in the tool name — the user opted in to lossy image compression.

We migrated to pikepdf in June 2026 from PyPDF2. PyPDF2's compress_content_streams() method was silently corrupting modern PDFs that use compressed object streams — pages would render blank in the output even though the file structure was valid. Pikepdf doesn't have that class of bug because it wraps the actively-maintained qpdf C++ codebase.

Decision tree

  • Text-heavy PDF, small-to-medium size (contracts, reports, articles) → pikepdf/qpdf. Lossless, fast, ~50% savings.
  • Image-heavy PDF and you can't hit a size cap (scans, brochures, photo books for email/portal) → Ghostscript. Lossy, much smaller output.
  • Signed PDFpikepdf/qpdf only. Ghostscript will invalidate the signature.
  • You're writing Pythonpikepdf. Same engine as qpdf with a friendlier API.
  • You need a hard size target (under 100 KB, under 2 MB)Ghostscript with successive presets, or our compress-to-size tool which automates the loop.

Frequently asked questions

Which PDF compression library is best?

Depends on the document. For text-heavy PDFs (contracts, reports): qpdf or pikepdf — lossless, signature-safe, typically 20-60% savings. For image-heavy PDFs (scans, photo brochures): Ghostscript — 60-90% savings but visibly reduces image quality and breaks signatures. Pick qpdf/pikepdf as the default; switch to Ghostscript only when size matters more than fidelity.

What is the difference between qpdf and pikepdf?

Same engine, different language. qpdf is the C++ tool and library; pikepdf is the Python binding around it. Output is byte-equivalent for the same options.

Why does Ghostscript compress more than qpdf?

Ghostscript downsamples embedded images and re-encodes them at lower quality. qpdf/pikepdf never touch image data. Image-heavy PDFs see massive Ghostscript savings; text-heavy PDFs see almost no difference.

Will compression break my signed PDF?

qpdf/pikepdf preserve signed PDFs intact (they preserve the byte ranges the signature commits to). Ghostscript almost always invalidates signatures. If your PDF is signed, use qpdf or pikepdf.

Compress your PDF in-browser — pikepdf engine, free

Lossless container repack via the pikepdf/qpdf engine. Preserves signatures, form fields, and image quality. Typical 20–60% savings on text PDFs. No upload daily cap, no watermark.

Open the Compress PDF Tool →

Found this useful? Share it with others.

Why ImageAndPDF

100% Free

No hidden costs, no credit card, no signup required.

Private & Secure

Many tools process files in your browser; some features use secure server processing.

Instant Results

Cloud-powered processing. Most files done in seconds.

Works Everywhere

Any browser, any device. Nothing to install.

Ready to work with your files?

30+ free tools for PDFs, images, and documents. No signup needed.

Browse All Tools
Kummari Achyuth
Kummari AchyuthMaintainer

Kummari Achyuth is a software engineer and the founder of ImageAndPDF. He started the project after running into the same frustration most people meet with online file tools — uploads to unknown servers, daily limits, watermarks, and signups before any work could be done. His response was to build a suite of utilities that run almost entirely in the browser, using open-source libraries like pdf-lib, PDF.js, and ONNX Runtime, so files never have to leave the device for most operations. He works primarily on the platform's performance and privacy architecture: the rendering pipeline, the in-browser processing pathways, and the on-device AI models for background removal and image upscaling.