ZingPDF logo

Guide

How to compress a PDF in C#

Call Compress(dpi, quality) on the loaded document, then save the result.

This recompresses eligible streams in the PDF. The main setting you will usually care about is the JPEG quality value.

The shortest working example

Load the PDF, call Compress(...), then save.

using ZingPDF;

using var pdf = Pdf.Load(File.OpenRead("input.pdf"));
using var output = File.Create("compressed.pdf");

pdf.Compress(dpi: 144, quality: 75);
await pdf.SaveAsync(output);

Arguments

The method takes two values:

  • dpi: reserved for future image downsampling behavior and must be greater than zero
  • quality: JPEG recompression quality from 1 to 100

In practice, the quality setting is the one that matters most today.

What compression does here

Compression works on eligible streams in the document and can recompress JPEG image streams.

If your file is image-heavy, this is the high-level path to try before moving into lower-level PDF stream work.

Need to watermark before the final save?

Compression often sits near watermarking or metadata updates in the same output path.

Read How to add watermarks to PDFs in C#.

Open save docs View pricing