PDF Compression

IronPDF provides support for compressing PDFs, primarily by reducing the size of embedded images within the document using the CompressAndSaveAs method.

When resizing JPEGs, the quality setting determines the balance between file size and image clarity. A quality of 100% results in almost no noticeable loss, while 1% produces a very low-quality image. Generally, 90% and above is considered high quality, 80%-90% is medium quality, and 70%-80% is low quality. Reducing the quality below 70% can significantly lower the file size but may result in visibly lower image quality.

It's recommended to experiment with different quality values to find the ideal balance between file size and image clarity for your specific needs. Keep in mind that the degree of visible quality reduction depends on the original image; some images may degrade more noticeably than others.

5 Steps to Compress PDF Files in C#

First, we will need to load the PDF document that needs to be compressed. This can be done with the PdfDocument class, which can be used to load an existing PDF file from the given file path.

Now, we will demonstrate compressing images within the PDF with a specified quality. To do this, we will use the CompressAndSaveAs method and pass it the output file path along with the quality at which we want it to compress. This method will compress all of the images within our PDF document to 60% of their original quality and save the result in a single call. The quality parameter is an integer from 1 (lowest quality, highest compression) to 100 (highest quality, least compression). This reduces the file size, but you will need to be aware that it can result in some loss of image clarity.

Next, let's demonstrate another approach using a higher quality value. To do this, we will again use the CompressAndSaveAs method, this time passing a quality of 90 to preserve more image detail while still reducing file size. A higher quality value keeps the images sharper at the cost of a smaller reduction in file size.

This second call again compresses and saves the PDF to the specified location in one step. This approach is useful when optimizing PDFs for smaller file sizes, such as for web or email use, while balancing quality and compression.

Optimize your PDFs with our Compression Guide.

Ready to Get Started?
Nuget Downloads 20,296,129 | Version: 2026.7 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast? PM > Install-Package IronPdf
run a sample watch your HTML become a PDF.