Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Dec 08, 2023 1:24 am

Hi..

I found that to compress the size of a PDF, you need to use a method like it.
`PdfCompressor compressor = new PdfCompressor(pdfPath);
compressor.CompressToFile("Compressed.pdf");
`.

Is there a way to compress a PDF when loading it, performing a specific task, and saving it?
Before saving, there was a compression option, but it didn't work.

Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(fileName);

//..... some task

doc.CompressionLevel = PdfCompressionLevel.Best; // is not working
doc.SaveToFile(fileName);



------
Add content

Also, when using `PdfCompressor`, the compression rate seems to be too high even though the ImageQuality is set to high (4.33MB -> 670KB). There are some images in my PDF file, but the image resolution seems to be lowered too much. I want about half the compression ratio, is there a higher option?
Code: Select all
            PdfCompressor compressor = new PdfCompressor(fileName);
            compressor.Options.ImageCompressionOptions.CompressImage = true;
            compressor.Options.ImageCompressionOptions.ImageQuality = ImageQuality.High;
            compressor.Options.ImageCompressionOptions.ResizeImages = true;
            compressor.Options.TextCompressionOptions.CompressFonts = true;
            compressor.Options.RemoveMetadata = true;
            compressor.CompressToFile(saveName);

Sungkyu_min
 
Posts: 36
Joined: Fri Jan 07, 2022 5:53 am

Fri Dec 08, 2023 5:48 am

Hi,

Thank you for your inquiry.
You can refer to the following link to help you achieve the effect of compressing document. If the issue still exists, please offer your file to help us do further investigation, you can attach here or send it to us via email ([email protected] ). Thank you in advance.

Website link: https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Document-Operation/How-to-Compress-PDF-Document-in-C-VB.NET.html

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Return to Spire.PDF

cron