Aspose Pdf size increase after attaching png image in page

Hi team,

We have 206 kb size of pdf and 60 kb png image…

After attaching the image to the Pdf page, its size increases to 456 kb, which is twice the original Pdf file.
please refer attached zip file.

AsposePdfSizeIncreaseIssue.zip (258.6 KB)

@cyginfo

Looks like you are not optimizing the PDF document. Please try to optimize it after adding image and see if the output file size is reduced. If issue still persists, please let us know.

Hi @asad.ali
We have tried to using pdf Optimize as you refer,
We tried to reduce image quality as well and also test with compress image option.
but pdf size not getting optimize.

@cyginfo

We added below code snippet after the save() call in your code and obtained the attached PDF document which size seems reduced. We used 23.8 version of the API. Can you please make sure that you are using the latest version of the API?

doc.Save(outStream, SaveFormat.Pdf);
outStream.Seek(0, SeekOrigin.Begin);
Document pdf = new Document(outStream);
var optimizationOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
optimizationOptions.RemoveUnusedObjects = true;
optimizationOptions.RemoveUnusedStreams = true;
optimizationOptions.AllowReusePageContent = true;
optimizationOptions.LinkDuplcateStreams = true;
optimizationOptions.UnembedFonts = true;
optimizationOptions.ImageCompressionOptions.CompressImages = true;
optimizationOptions.ImageCompressionOptions.ImageQuality = 50;
optimizationOptions.ImageCompressionOptions.ResizeImages = true;
optimizationOptions.RemovePrivateInfo = true;
pdf.OptimizeResources(optimizationOptions);
pdf.Optimize();
pdf.Save(dataDir + "optimized" + DateTime.Now.Millisecond + ".pdf");

optimized397.pdf (137.9 KB)