Converting pdf to png wrong image size

Hi Everyone,


I am trying to convert the attached PDF to PNG using the below snippet. I am trying to make a pdf viewer.

PngDevice pngDevice = new PngDevice(resolution);
pngDevice.process(pdfPage, imageStream);
array = imageStream.toByteArray();

However, I am getting the attached screenshot as result. Notice that I am facing the same problem whiletrying the .Net version of pdf.

Hi There,


Thanks for contacting support.

I have tested the scenario with following code snippet using Aspose.Pdf for Java 17.3.0 and it is working fine. Please use the following code snippet to fix it. I have also attached the generated PNG file for your reference.

JAVA

com.aspose.pdf.Document doc = new com.aspose.pdf.Document(dataDir + “Utilization+Review+Committee+(1).pdf”);
com.aspose.pdf.devices.PngDevice png = new com.aspose.pdf.devices.PngDevice(new com.aspose.pdf.devices.Resolution(300));
if(!doc.getPages().get_Item(1).getCropBox().equals(doc.getPages().get_Item(1).getMediaBox())) {
png.setCoordinateType(PageCoordinateType.MediaBox);
}
png.process(doc.getPages().get_Item(1),dataDir + “test.png”);

If you still face any issue or need further assistance, please feel free to contact us.

Best Regards,