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.
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);
}
}
}
Discover the PDF compression feature’s many method.
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.
Font resources contribute to larger file sizes. To reduce PDF size, eliminate unused glyphs and unnecessary font tables from embedded fonts within the document.
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.
Optimizing page content involves removing unnecessary comments, white spaces, converting end-of-line characters, and compressing uncompressed content to enhance efficiency.
Discover valuable resources from our blog and knowledge base to enhance your efficiency in PDF Compression.
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Product Updates
Technical Support
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.
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.