Skip to content

PDF compression produces very little size reduction #114

Description

@serhumanos001

Hi! I'm testing the PDF compression feature in PDFCraft and I'm trying to understand how the different compression levels are expected to work.

I tested the Low compression option on a PDF containing a significant amount of content/images, but the resulting file was only about 1 MB smaller than the original.

For example:

Original PDF:    XX MB
Low compression: XX MB
Reduction:       ~1 MB

I investigated the Docker image and found that workers/compress.worker.js uses coherentpdf:

coherentpdf.compress(pdf);
coherentpdf.squeezeInMemory(pdf);

For low, it then generates and compresses object streams:

coherentpdf.toMemoryExt(
  pdf,
  false,
  false,
  false,
  true,
  true
);

From what I can see, this appears to optimize PDF streams and structure, but it does not seem to perform image downsampling or JPEG recompression.

I also noticed that the project includes PyMuPDF WASM, Pillow, OpenCV, and QPDF WASM, so I was wondering whether there is another image-compression step elsewhere in the application.

Questions

  1. Is the current Low compression level expected to only perform structural/stream compression?
  2. Does PDFCraft currently perform any image downsampling or JPEG/PNG recompression when using Low, Medium, or High?
  3. If not, is image recompression planned for the compression feature?
  4. What is the intended difference in compression behavior between Low, Medium, and High?
  5. Is there a recommended way to achieve significantly smaller PDFs, especially for PDFs containing scanned pages or high-resolution images?

For example, I would expect something along these lines for image-heavy PDFs:

Low:     aggressive image compression / downsampling
Medium:  balanced compression
High:    higher quality with moderate compression
Maximum: preserve original image quality

I'm asking because a PDF that is, for example, 30–50 MB may only become approximately 1 MB smaller with Low, which seems much less than what I would expect from a PDF compression tool.

Thanks!

Activity

  1. PDFCraftTool commented on Sep 4, 2026

    @PDFCraftTool
    Owner

    Hi @username,

    Thank you very much for your insightful feedback and for looking into our worker implementation! Your observation was spot on.

    1. Root Cause of the ~1 MB Reduction on Low

    In src/lib/pdf/processors/compress.ts, our standard compression pipeline uses coherentpdf for structural and object stream optimization, followed by a second pass with PyMuPDF WASM for image downsampling and JPEG re-encoding.

    However, in a recent regression patch aimed at avoiding over-compression on small vector graphics, an inadvertent check was introduced:

    const shouldOptimizeImages = compressOptions.optimizeImages && 
                                 originalSize > 500 * 1024 && 
                                 compressOptions.quality !== 'low'; // <-- This mistakenly bypassed image optimization for Low!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions