Hello we have been getting large PDF files in the 80 MBs range and need to compress these. Some clients are scanning in too high resolution and in color. I have tried several Telerik code examples for importing and exporting, but have had no successful attempts at reducing the file size. Most made the same PDF size, but some examples resulted in larger PDF sizes. There was a grayscale example in the a thread, but that increased the file size by about 50% regardless of the PDF. Is there an example on importing, running a compression scheme, and then exporting that results in smaller PDFs?
5 Answers, 1 is accepted
When you import and then export a PDF file with RadPdfProcessing the exported file is always compressed the best way RadPdfProcessing can. That said, in case the original file has uncompressed content, it will be compressed on export with the RadPdfProcessing. There is a property - ImageQuality that can change the default quality compression however it does so for newly created images and not for the ones imported from the original PDF file.
There is a feature request in our public portal - Introduce API allowing to optimize and reduce the size of existing PDF files. You could upvote it and subscribe for it in order to get notified when its implementation status changes.
Yes, I was trying the ImageQuality on the lowest setting and it would output about same size but larger. For instance this 147,295 KB pdf outputs to 148,398 KB. Why would this output to a larger pdf when the ImageQuality is set to low?
public static readonly string RootDirectory = AppDomain.CurrentDomain.BaseDirectory;
public static readonly string InputFileName = RootDirectory + "InputFiles\\721906.pdf";
static void Main()
private static void TestOutput()
PdfFormatProvider provider = new PdfFormatProvider();
PdfExportSettings settings = new PdfExportSettings();
settings.ImageQuality = ImageQuality.Low;
using (Stream stream = File.OpenRead(InputFileName))
RadFixedDocument document = provider.Import(stream);
provider.ExportSettings = settings;
Stream outStream = File.Create("output.pdf");
The ImageQuality changes the quality compression for newly created images and not for the ones imported from the original PDF file. This is why the size of the document is not reduced. In case new images are being added to the document their quality will be affected by the ImageQuality setting.
As for why the size increased, this is caused by the fact that when a document is imported and then exported, the PdfProcessing embeds fonts in it. According to PDF Reference specification all fonts used in the document should be embedded except from the 14 Standard PDF fonts.
Hope this clarifies why has the document size increased a bit.
Should you have any other questions, please let me know.
You are right, it's possible to iterate the content elements, detect the original images, remove them, and insert new images with modified image source, or with ImageQuality set to lower values, for example: