Optimizing and Reducing the Size of PDF Files with RadPdfProcessing
Environment
| Version | Product | Author |
|---|---|---|
| 2024.2.426 | RadPdfProcessing | Desislava Yordanova |
Description
When you handle PDF files, you often need to optimize and reduce their size without compromising the content quality. This requires applying better compression to stream objects and adjusting image quality settings. This article shows how to:
- Compress the content inside a PDF document
- Fine-tune the settings to lower the image quality in a PDF for size optimization
- Optimize the font embedding in RadPdfProcessing
Solution
To optimize and reduce the size of existing PDF files with RadPdfProcessing, follow these steps:
-
Adjust Image Quality: Set the ImageQuality to a lower setting to reduce the size of images within the PDF. Lower image quality results in smaller file sizes.
csharppdfFormatProvider.ExportSettings.ImageQuality = ImageQuality.Low;For more information on setting image quality, see the ImageQuality documentation.
-
Apply Image Compression: Specify the types of ImageCompression to use.
FlateDecodeis recommended for effective compression.csharppdfFormatProvider.ExportSettings.ImageCompression = new ImageFilterTypes[] { ImageFilterTypes.FlateDecode };For more information on image compression settings, see the ImageCompression documentation.
-
Enable Stream Compression: Stream compression reduces the size of non-image content in the same way as image compression.
csharppdfFormatProvider.ExportSettings.StreamCompression = new StreamFilterTypes[] { StreamFilterTypes.FlateDecode };For more information on stream compression, see the StreamCompression documentation.
-
Optimize Font Embedding: Starting with Q2 2024, you can use
FontEmbeddingType.Subsetto export only the necessary parts of TrueType Fonts (TTF). This reduces the PDF file size.csharppdfFormatProvider.ExportSettings.FontEmbeddingType = FontEmbeddingType.Subset;For more information on font embedding types, see the FontEmbeddingType documentation.
Notes
- Reduce the size of PDF files carefully. Lowering image quality and applying aggressive compression can affect the visual fidelity of the document.
- Always test the output PDF to ensure the optimizations meet your requirements.