IRONSOFTWAREHOME
PDF Compression
using IronPdf;

var pdf = new PdfDocument("document.pdf");

// Quality parameter can be 1-100, where 100 is 100% of original quality
pdf.CompressAndSaveAs("document_compressed.pdf", 60);

// Higher quality setting for better image preservation - the API provides automatic optimization
pdf.CompressAndSaveAs("document_scaled_compressed.pdf", 90);
Imports IronPdf

Dim pdf = New PdfDocument("document.pdf")

' Quality parameter can be 1-100, where 100 is 100% of original quality
pdf.CompressAndSaveAs("document_compressed.pdf", 60)

' Higher quality setting for better image preservation - the API provides automatic optimization
pdf.CompressAndSaveAs("document_scaled_compressed.pdf", 90)
NuGet Download
PM > Install-Package IronPdf
PDF Compression

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.
View on GitHub

Ready to Get Started?

Nuget Downloads 21,062,892Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999