I’m using this code to compress pdf:
var doc = new Document(inputPath);
var opts = new OptimizationOptions
{
AllowReusePageContent = true,
LinkDuplcateStreams = true,
RemoveUnusedObjects = true,
RemoveUnusedStreams = true,
SubsetFonts = true,
UnembedFonts = true,
CompressObjects = true,
ImageCompressionOptions =
{
Encoding = ImageEncoding.Jpeg,
CompressImages = false,
ImageQuality = 100,
ResizeImages = false
}
};
This works fine but if I add any image compression:
opts.MaxResoultion= 150;
opts.ImageCompressionOptions.ImageQuality = 20;
opts.ImageCompressionOptions.CompressImages = true;
opts.ImageCompressionOptions.ResizeImages = true;
Instead of this:
image.jpg (141.4 KB)
I get:
image.png (119.8 KB)
This happens with any value for image quality.
Problematic file:
https://cdn.filestar.com/uploads/b869fdda-d7b8-4bc8-a1dd-0abdd00160cf/upload.zip
@nielsbosma
Have you tried using 23.9 version? We used it and faced IndexOutOfRange Exception. Can you please share the complete code snippet? We will further proceed to assist you accordingly.
var doc = new Document(inputPath);
var opts = new OptimizationOptions
{
AllowReusePageContent = true,
LinkDuplcateStreams = true,
RemoveUnusedObjects = true,
RemoveUnusedStreams = true,
SubsetFonts = true,
UnembedFonts = true,
CompressObjects = true,
ImageCompressionOptions =
{
Encoding = ImageEncoding.Jpeg,
CompressImages = false,
ImageQuality = 100,
ResizeImages = false
}
};
opts.MaxResoultion= 150;
opts.ImageCompressionOptions.ImageQuality = 20;
opts.ImageCompressionOptions.CompressImages = true;
opts.ImageCompressionOptions.ResizeImages = true;
doc.Save(outputPath, new PdfSaveOptions());
I’m using Aspose.PDF.Drawing version 23.8.0. I don’t see any 23.9.0 in my nuget feed.
@nielsbosma
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-55535
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
The issues you have found earlier (filed as PDFNET-55535) have been fixed in Aspose.PDF for .NET 24.6.