We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

pngDevice generate different sized png file for the same pdf file

Hi. I am trying to convert a pdf page into a png file.
Only the first trial after launching the project is different.
For example, the first outcome is 1,182KB after then always 1,199KB.

I suspect memory leaks because it works fine only the first or second time after I re-launch the project.

I am sharing a code snippet. It is .net framework, c#.

 using (Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(strFilePath))
                Aspose.Pdf.PageCollection pageCollection = pdfDocument.Pages;
                Aspose.Pdf.Page pdfPage = pageCollection[selectedPage];
                using (MemoryStream imageStream = new MemoryStream())

                    int quality = GetResulutionValueByProject(projectInfo);

                    Resolution resolution = new Resolution(quality);
                    PngDevice pngDevice = new PngDevice(resolution);
                    pngDevice.Process(pdfPage, imageStream);
                    using (Bitmap img = new Bitmap(imageStream))
                        //Console.WriteLine(string.Format("rectHeight : {0} rectWidth{1}", rect.Height, rect.Width));
                        Console.WriteLine(string.Format("imageHeight : {0} imageWidth{1}", img.Height, img.Width));


You may be available duplicating the same problem if you convert the same file in a loop.
If you need further information, Please let me know.


Would you please also share the sample PDF document for our reference which you are converting at your side? We will test the scenario in our environment and address it accordingly.

Iā€™d love to, but our company policy highly prohibits send out any of the documents outside of the company, even if I remove all of the information on it.

I found out the problem occurs mostly on a certain document which is drawing.
And the problem happens on this part

PngDevice pngDevice = new PngDevice(resolution);
pngDevice.Process(pdfPage, imageStream);

If I put PngDevice width and height of the document instead of a resolution,
it works fine. The problem is, I have to convert the PDF into Png file with the best quality
as it is used for object detection.

Hope there is a solution you can provide.
Thank you.

Hi. I created a simple project and found out there is no problem.
I think it was something related to memory.
I solved the problem by creating a webservice.

But if you know the possible reason for this, please share your idea.


It is good to know that you were able to sort your issue out. We regularly check our API for performance related scenarios like memory consumption and improve it in order to perform better with every new release.

We are afraid that we cannot comment further on this scenario for sure as we did not notice such issue at our side with our sample files. In case you can share any sample file with us, we will be able to test the scenario and share our feedback with you. You can also share it in a private message if you find it suitable. This way the files can only be accessed by Aspose Staff.

You can send a private message by clicking over username and pressing Blue Message Button.

Thanks for your support.

1 Like