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);