Free Support Forum -

Convert PNG to PDF using Aspose.Imaging for Java - java.lang.Exception occurred


asposeImage = (PngImage) com.aspose.imaging.Image.load(imageFilename);

Exception seen:

At 2019-09-20 17:04:25 Failure: Image loading failed.

java.lang.Exception: class com.aspose.imaging.coreexceptions.ImageLoadException: Image loading failed. —> class com.aspose.imaging.coreexceptions.imageformats.PngImageException: Could not read data. Source)
com.aspose.imaging.internal.ct.k.a(Unknown Source)
com.aspose.imaging.internal.eB.C.load(Unknown Source)
com.aspose.imaging.Image.a(Unknown Source)
com.aspose.imaging.Image.load(Unknown Source)

FC5F1998104EB92469CB14070628073616BB28F9.png (7.5 KB)

This PNG opens fine in Preview.


I have worked with the sample file shared. An issue with ID IMAGINGJAVA-1442 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

aspose.pdf.Image creates a blank PDF for the same above PNG file, with no exceptions thrown

Is this expected? If so, how can we check if the generated PDF is going to be blank?
If not, could you please open a different bug for this?

Document doc = new Document();
// Add a page to pages collection of document
Page page = doc.getPages().add();
// Load the source image file to Stream object fs = new;
// Create an image object
Image image1 = new Image();
// Add the image into paragraphs collection of the section
// Set the image file stream

// Save resultant PDF file;


Can you please use Aspose.Imaging for Java to convert PNG image to PDF and if there is still an issue than please share feedback with us. Also please visit this documentation link for source code.

The issues you have found earlier (filed as IMAGINGJAVA-1442) have been fixed in this update.