How to Compress PDFs

by Chaknith Bin

PDF compression refers to the process of reducing the file size of a PDF (Portable Document Format) document. This compression is applied to make the PDF file more manageable for storage, sharing, and transmission, especially when dealing with large or image-rich documents.

Images typically occupy a significant portion of PDF file sizes because they are generally larger in size compared to text and other content. IronPdf offers PDF compression features that compresses the embedded images and reduces the tree structure that often accompanies table data in PDFs.

C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf

Download DLL

Download DLL

Manually install into your project

Compress Images Example

The way resizing JPEGs works, 100% quality has almost no loss, and 1% is a very low-quality output image.

  • 90% and above: considered high-quality
  • 80%-90%: considered medium-quality
  • 70%-80%: considered low-quality

Feel free to explore various values to understand the trade-off between quality and file size. It's important to note that the quality reduction will vary based on the type of input image, and certain images may experience more noticeable clarity reduction than others.

using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument pdf = renderer.RenderUrlAsPdf("");

// Compress images in the PDF

Imports IronPdf

Private renderer As New ChromePdfRenderer()

Private pdf As PdfDocument = renderer.RenderUrlAsPdf("")

' Compress images in the PDF

VB   C#

Compress Images - Size Comparison

39.24% reduction in size!

Compress images - size comparison

Compress Tree Structure Example

This feature is used to reduce the size of the PDF by minimizing the tree structure created by the Chrome Engine. It works well with PDFs generated by the Chrome Engine from HTML containing extensive table data. Some PDF rendering engines might output PDF without this tree structure making the feature not effective.

The downside of removing all this tree structure is that for some PDFs, highlighting text or extracting may not work as effectively.

Let's use the table.pdf file to test out the CompressStructTree method.

using IronPdf;

PdfDocument pdf = PdfDocument.FromFile("table.pdf");

// Compress tree structure in PDF

Imports IronPdf

Private pdf As PdfDocument = PdfDocument.FromFile("table.pdf")

' Compress tree structure in PDF

VB   C#

Compress Tree Structure - Size Comparison

67.90% reduction in size! This percentage increases with larger table PDF.

Compress tree structure - size comparison

Chaknith Bin

Software Engineer

Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.