7 Ways to Compress PDF Files in C#, VB.NET | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (166).NET Core  (29).NET MAUI  (117)Angular  (93)ASP.NET  (51)ASP.NET Core  (81)ASP.NET MVC  (89)Azure  (39)Blazor  (174)BoldSign  (2)DocIO  (23)Essential JS 2  (95)Essential Studio  (186)File Formats  (40)Flutter  (124)JavaScript  (210)Microsoft  (117)PDF  (72)React  (84)Succinctly series  (130)Syncfusion  (686)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (41)Windows Forms  (59)WinUI  (60)WPF  (143)Xamarin  (158)XlsIO  (27)Other CategoriesBarcode  (5)BI  (29)Bold BI  (6)Build conference  (8)Business intelligence  (54)Button  (4)C#  (127)Chart  (73)Cloud  (13)Company  (445)Dashboard  (8)Data Science  (3)Data Validation  (7)DataGrid  (60)Development  (494)Doc  (7)DockingManager  (1)eBook  (98)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (25)Extensions  (21)File Manager  (5)Gantt  (16)Gauge  (11)Git  (5)Grid  (28)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (378)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (34)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (10)Road Map  (11)Scheduler  (47)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (25)Solution Services  (3)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (107)UI  (264)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (24)Visual Studio Code  (17)Web  (461)What's new  (245)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)

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

Syncfusion Essential PDF is a .NET PDF library that can be used to optimize or compress your PDF documents. Reducing the PDF file size can help you by optimizing bandwidth cost, network transmission, and digital storage. It is especially useful in areas like archiving, emailing, and using PDF documents in web-based applications. Essential PDF supports the following optimizations:

In this blog, we will look at each of these optimizations and how to implement them.

Reducing PDF file size by shrinking all images

PDF files may contain many images. Removing the images from a PDF file is usually not an option since they are necessary for many PDFs. Downsampling the images will decrease the number of pixels and is possibly the most effective way to reduce PDF file size. The user can control the PDF file size with respect to the quality of the image.

//Create a new compression option object.
PdfCompressionOptions options = new PdfCompressionOptions();
options.CompressImages = true;
//Image quality is a percentage.
options.ImageQuality = 10;

Reducing PDF file size by optimizing fonts

Not all the glyphs data and font tables are required to render the text in the PDF document. Remove the unused glyphs and unwanted font tables from the embedded fonts in a PDF document to make it smaller.
PdfCompressionOptions options = new PdfCompressionOptions();
options.OptimizeFont = true;

Reducing PDF file size by removing metadata

Sometimes unnecessary metadata might be present in the PDF file. Remove the unnecessary metadata, to reduce the size of the PDF.

PdfCompressionOptions options = new PdfCompressionOptions();
options.RemoveMetadata = true;

Reducing PDF file size by optimizing page contents

Optimizing the page contents will remove unwanted commented lines, white spaces, convert end-of-line characters to spaces and compress all uncompressed contents.

PdfCompressionOptions options = new PdfCompressionOptions();
options.OptimizePageContents = true;

Reducing PDF file size by disabling incremental updates

Incremental update is an option available to update the PDF file incrementally without rewriting the entire file. Here, changes are appended to the end of the file, leaving its original contents intact. Disabling the incremental update will rewrite the entire file, which results in a smaller PDF.

//Load the existing PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"input.pdf");
//Restructure the complete document.
loadedDocument.FileStructure.IncrementalUpdate = false;

Reducing PDF file size by removing form fields

Removing or flattening form fields can help reduce your file size. When form fields and their values are not necessary, they can be removed. When they are necessary but require no further editing, they can be flattened. Both of these actions will result in a reduced file size.

public void RemoveFormFields(PdfLoadedDocument ldoc, bool flatten)
    if (flatten)
        ldoc.Form.Flatten = true;
        int count = ldoc.Form.Fields.Count;
        for (int i = count - 1; i >= 0; i--)

Reducing PDF file size by removing annotations

Removing or flattening annotations can help reduce your file size. Annotations and their contents can be removed when they are not needed. When they are necessary but do not require additional editing, they can be flattened. Both of these options will result in a reduced file size.

public void RemoveAnnotations(PdfLoadedDocument ldoc, bool flatten)
    foreach(PdfPageBase page in ldoc.Pages)
        if (flatten)
           page.Annotations.Flatten = true;
            int count = page.Annotations.Count;
            for (int i = count - 1;i >= 0; i--)

PDF compression options

GitHub sample

For more details about this sample, refer to the complete compress PDF application demo on the GitHub repository.

Wrapping up

As you can see, Essential PDF provides a variety of optimizing mechanisms for compressing a PDF document. Use them effectively to generate compressed documents for increased efficiency and productivity in a document management system. Take a moment to peruse the documentation, where you’ll find other options and features, all with accompanying code examples.

If you are new to our PDF library, it is highly recommended that you follow our Getting Started guide.

If you’re already a Syncfusion user, you can download the product setup here else, you can download a free, 30-day trial here.

Have any questions or require clarifications about these features? Please let us know in the comments below, you can also contact us through our support forum or Direct-Trac. We are happy to assist you!

If you liked this blog post, we think you’ll also like the following related blog posts:


Share this post:

Comments (2)


Is it possible to reduce a pdf document 92, 032 KB to 1, 749 KB?
I need to integrate it into my application developed at home with winforms vb.net


Yes, we can compress a PDF file from 92 MB to 1.749 MB but it is based on the input document structure, usually we will compress PDF inner objects which is already not in the best compression.
For example if a document has more number of images with low compression then we can compress the document further by shrinking all the images to best compression also we can use other options provided in this blog
• Optimizing fonts.
• Removing metadata.
• Optimizing page content.
• Disabling incremental updates.
• Removing or flattening form fields.
• Removing or flattening annotations.
Usually we cannot further compress the PDF document if it is already in the best compression state.


Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top