We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Syncfusion Feedback

Syncfusion is trusted by the world’s leading companies

Syncfusion Trusted Companies

Overview

The Syncfusion .NET PDF Library provides a feature to compress PDF documents programmatically. Shrink file sizes without losing quality, making your PDFs perfect for printing, archiving, and sharing online. The feature is easy to use, giving you the power to customize your PDFs exactly how you want them.

The PDF Compression feature works seamlessly across platforms, including Windows, macOS, Linux, Android, and iOS through any .NET-based application, such as ASP.NET Core, ASP.NET MVC, Blazor, .NET MAUI, Xamarin, WinForms, WPF, and WinUI.

How to compress a PDF file in C#

This example code shows how to compress PDF files using the Syncfusion .NET PDF Library, with just a few lines of code. You can reduce PDF file size with various settings.

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

// Open a file stream to read the input PDF file.
using (FileStream fileStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
{ 
    // Create a new PdfLoadedDocument object from the file stream.
    using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
    { 
        // Create a new PdfCompressionOptions object.
        PdfCompressionOptions options = new PdfCompressionOptions(); 
        // Enable image compression and set image quality.
        options.CompressImages = true; 
        options.ImageQuality = 50; 
        // Enable font optimization.
        options.OptimizeFont = true; 
        // Enable page content optimization.
        options.OptimizePageContents = true; 
        // Remove metadata from the PDF.
        options.RemoveMetadata = true; 
        // Compress the PDF document.
        loadedDocument.Compress(options);
        // Save the document into a memory stream.
        using (MemoryStream outputStream = new MemoryStream()) 
        { 
            loadedDocument.Save(outputStream); 
        } 
    } 
}

Various options of PDF Compression

Discover the PDF compression feature’s many method.

Compress images in .NET PDF.

Shrink or compress images

PDFs often have lots of necessary images. Instead of removing them, you can reduce the file size by lowering the image quality. This way, you can control the size of the PDF while keeping the essential images intact.

Optimize fonts in .NET PDF.

Optimize fonts

Font resources contribute to larger file sizes. To reduce PDF size, eliminate unused glyphs and unnecessary font tables from embedded fonts within the document.

Remove metadata in .NET PDF.

Remove metadata

Removing unnecessary metadata from a PDF file involves eliminating any additional information or properties embedded within the file that are not essential for its content or functionality.

Optimize page content in .NET PDF.

Optimize page content

Optimizing page content involves removing unnecessary comments, white spaces, converting end-of-line characters, and compressing uncompressed content to enhance efficiency.

Explore references for PDF Compression

Discover valuable resources from our blog and knowledge base to enhance your efficiency in PDF Compression.

7 Ways to Compress PDF Files in C#

Blog

7 Ways to Compress PDF Files in C#, VB.NET

Disabling incremental updates in .NET PDF

Documentation

Disabling incremental updates

Easily Publish ASP.NET Core App in Linux Docker that Compresses PDF Documents

Blog

Easily Publish an ASP.NET Core App in Linux Docker that Compresses PDF Documents

Syncfusion .NET PDF Library Resources

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

Struggling to decide on the right product?

Our comprehensive competitor comparison of PDF framework will guide you to the perfect choice.

tick-mark 20+ Conversions support
tick-mark 50+ interactive demos
tick-mark 1.7M+ downloads
competitive-banner-FT-image

Frequently Asked Questions

PDF compression is the process of reducing the file size of a PDF document while maintaining its visual quality and content integrity. This is often done to make the file more manageable for storage, sharing, or uploading purposes.

PDF compression should not significantly affect the visual quality or readability of the document. However, extreme compression settings or aggressive compression methods may result in some loss of quality, particularly for images.

Once a PDF has been compressed, it may not be possible to fully revert it to its original uncompressed state.

Compressing a PDF can significantly reduce its file size, making it easier to share via email, upload to websites, or store on your device or cloud storage. It also helps conserve bandwidth when transferring large files over the internet.

Syncfusion’s PDF compression algorithm optimizes the internal structure of PDF files, reducing redundant data and applying efficient compression techniques to images and other elements, resulting in smaller file sizes.

Our Customers Love Us

Having an excellent set of tools and a great support team, Syncfusion reduces customers’ development time.
Here are some of their experiences.

Rated by users across the globe

Want to create, view, and edit PDF files in C# or VB.NET?

Start a free 30-day evaluation today!
DOWNLOAD FREE TRIAL

No credit card required.

Mobile Free Evaluation Section

Awards

Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion is proud to hold the following industry awards.

Scroll up icon