The Syncfusion® .NET PDF library that can be used to optimize or compress your PDF documents and which supports the following optimizations:
- Shrinking all images
- Optimizing fonts
- Removing metadata
- Optimizing page content
- Disabling incremental updates
- Removing or flattening form fields
- Removing or flattening annotations
This repository contains the example optimize PDF document with multiple ways.
Sample name | Description |
---|---|
Compress PDF | Demonstrates the optimization of an existing PDF document based on image quality, page content, metadata, annotation, form fields, incremental update and font to reduce the file size of the PDF document. |
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;
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;
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.RemoveMetadata = true;
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;
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;
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;
}
else
{
int count = ldoc.Form.Fields.Count;
for (int i = count - 1; i >= 0; i--)
{
ldoc.Form.Fields.RemoveAt(i);
}
}
}
Removing or flattening annotations can help reduce your file size.
public void RemoveAnnotations(PdfLoadedDocument ldoc, bool flatten)
{
foreach(PdfPageBase page in ldoc.Pages)
{
if (flatten)
{
page.Annotations.Flatten = true;
}
else
{
int count = page.Annotations.Count;
for (int i = count - 1;i >= 0; i--)
{
page.Annotations.RemoveAt(i);
}
}
}
}
- Download this project to a location in your disk.
- Open the solution file using Visual Studio.
- Rebuild the solution to install the required NuGet package.
- Run the application.
- Product page: Syncfusion® PDF Framework
- Documentation page: Syncfusion® .NET PDF library
- Online demo: Syncfusion® .NET PDF library - Online demos
- Blog: Syncfusion® .NET PDF library - Blog
- Knowledge Base: Syncfusion® .NET PDF library - Knowledge Base
- EBooks: Syncfusion® .NET PDF library - EBooks
- FAQ: Syncfusion® .NET PDF library - FAQ
- For any other queries, reach our Syncfusion® support team or post the queries through the community forums.
- Request new feature through Syncfusion® feedback portal.
This is a commercial product and requires a paid license for possession or use. Syncfusion’s licensed software, including this component, is subject to the terms and conditions of Syncfusion's EULA. You can purchase a licnense here or start a free 30-day trial here.
Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion® has more than 26,000+ customers and more than 1 million users, including large financial institutions, Fortune 500 companies, and global IT consultancies.
Today, we provide 1600+ components and frameworks for web (Blazor, ASP.NET Core, ASP.NET MVC, ASP.NET WebForms, JavaScript, Angular, React, Vue, and Flutter), mobile (Xamarin, Flutter, UWP, and JavaScript), and desktop development (WinForms, WPF, WinUI(Preview), Flutter and UWP). We provide ready-to-deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software.