Syncfusion Feedback

Compress PDFs in C# with the .NET PDF Library

The Syncfusion® .NET PDF Library offers powerful capabilities for creating, reading, and editing PDF documents. Users can compress PDF files, reducing file size while maintaining quality. This improves storage efficiency and enables faster file sharing.

Watch this video to see how to compress PDF files using the Syncfusion .NET PDF Library.

Watch the video

Compress PDF files and reduce file size in C#

Learn how to programmatically compress PDF documents and optimize file size in C# using the Syncfusion .NET PDF Library. This guide demonstrates image compression and PDF optimization techniques.

Step 1: Create a new C# Console Application project

Begin by creating a new C# Console Application project in Visual Studio or your preferred IDE to implement PDF compression functionality.

Step 2: Install Syncfusion PDF Imaging NuGet package

Install the Syncfusion.Pdf.Imaging.Net.Core NuGet package in your C# project from NuGet.org. This package provides compression and image optimization APIs.

Step 3: Add required namespaces for PDF compression

Import the following namespaces in your Program.cs file to access PDF compression classes and methods:

using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;

Step 4: Load the existing PDF document

Use the PdfLoadedDocument class to load your existing PDF file that you want to compress and optimize.

//Load the PDF document.
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
{
}

Step 5: Configure PDF compression options

Create a PdfCompressionOptions object and configure the compression settings. Enable image compression and set the desired image quality (0-100, where lower values mean higher compression).

Run

// Create a new PdfCompressionOptions object
PdfCompressionOptions options = new PdfCompressionOptions();
//Enable the compress image
options.CompressImages = true;
//Set the image quality
options.ImageQuality = 50;

Step 6: Apply compression and save the PDF document

Apply the configured compression settings to the loaded PDF document using the Compress method, then save the compressed PDF. The output file will have a reduced file size based on your compression settings.

// Compress the PDF document
loadedDocument.Compress(options);
//Save the PDF document
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));

Get started quickly by downloading the installer and checking license information on the Downloads page.

Syncfusion .NET PDF Library Resources

Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.