Slow pdf build with images


I am building a PDF doc with images. The doc can have up to 3 images on one page. There is multiple pages. It will run in about 6.7 secs with out the images and 291 seconds when I add the images. The images are “text”. I need them formatted to a dynamic size and converting pdfs to png seemed the easiest way to manage the text format. I have a method that calls the following code:
var optimizeOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
// RemoveUnusedObjects = false,
// RemoveUnusedStreams = true,
// LinkDuplcateStreams = true,
// AllowReusePageContent = true,
// UnembedFonts = false,
// MaxResoultion = 50,

            optimizeOptions.ImageCompressionOptions.ImageQuality = 50;
            optimizeOptions.ImageCompressionOptions.Version = Aspose.Pdf.Optimization.ImageCompressionVersion.Fast;
            optimizeOptions.ImageCompressionOptions.CompressImages = true;

After this code is where I add the requested images. There is a little bit of logic to determine which image to add and then it calls:
doc.Pages[ii].AddImage(PdfFolder + name, rec);
I am not sure how the optimization works. Am I using it correctly? Where should I place this code in relation to the doc and images? Is there a better way than what I am doing?



The Optimization is performed to reduce PDF size and erase duplicate streams from it. This functionality also offers various other options to perform as you can notice while using the API. In case you need to optimize PDF or reduce its size, you can run this code snippet after completing the document and saving it to the disk.

Do you need to add images inside PDF with equal dimensions or you need to add images in PDF in a way that their height and width would not change? If you are building PDF document with images then why do you need to convert PDF into PNG? Would you please elaborate a bit more so that we may further proceed to assist you accordingly.