Hello,
Thank you for your further inquiry and sorry to reply late for weekend.
Yes, Spire Office 6.4.2 can compress PDF files. The way we compress PDF files differs between our new version and the old version. I'm attaching both sets of code for your reference.
If there's any issue, please provide your PDF file for our further investigation. Thanks in advance!
New Version Compression Code:
- Code: Select all
PdfCompressor compressor = new PdfCompressor(PdfFileName);
TextCompressionOptions textCompression = compressor.Options.TextCompressionOptions;
textCompression.CompressFonts = true;
textCompression.UnembedFonts = true;
ImageCompressionOptions imageCompression = compressor.Options.ImageCompressionOptions;
imageCompression.ImageQuality = ImageQuality.Medium;
imageCompression.ResizeImages = true;
imageCompression.CompressImage= true;
compressor.CompressToFile(outputImagePath);
Old Version Compression Code:
- Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"CompressDocument.pdf");
//Compress the content in document
CompressContent(doc);
//Compress the images in document
CompressImage(doc);
//Save the document
doc.SaveToFile("CompressDocument_result.pdf");
static void CompressContent(PdfDocument doc)
{
//Disable the incremental update
doc.FileInfo.IncrementalUpdate = false;
//Set the compression level to best
doc.CompressionLevel = PdfCompressionLevel.Best;
}
static void CompressImage(PdfDocument doc)
{
//Disable the incremental update
doc.FileInfo.IncrementalUpdate = false;
//Traverse all pages
foreach (PdfPageBase page in doc.Pages)
{
if (page.ExtractImages() != null)
{
PdfImageInfo[] infos = page.ImagesInfo;
for (int i = 0; i < infos.Length; i++)
{
page.TryCompressImage(i);
}
}
}
}
Sincerely,
Doris
E-iceblue support team