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

Free Support Forum - aspose.com

Can't load a JPG image in Java

Hi,


I’m trying to use your image example on the documentation but I’m getting a strange error when trying to load the image via a URL.

Here’s my code:

private Pdf pdfForInvoiceTest2() {

final Pdf pdf1 = new Pdf();


// Create a section in the Pdf object

final Section sec1 = pdf1.getSections().add();

// Create an image object in the section

final aspose.pdf.Image img1 = new aspose.pdf.Image();

// Add image object into the Paragraphs collection of the section

sec1.getParagraphs().add(img1);

// Specify the Image file type as JPEG

img1.getImageInfo().setImageFileType(ImageFileType.Jpeg);

// Set the path of image file

img1.getImageInfo().setFile("http://www.johnhpanos.com/jpeg.jpg");

// Set the path of image file

img1.getImageInfo().setTitle("JPEG image");

// Save the Pdf

return pdf1;

}


this method is called in a method here:


final ByteArrayOutputStream outStream = new ByteArrayOutputStream();

try {

pdfForInvoiceTest2().save(outStream);

} catch (final Exception e) {

e.printStackTrace();

}

outStream.close();

return outStream.toByteArray();


The error I get is:


class com.aspose.ms.System.f: Invalid image handle in GetImageWidth method:-1

aspose.pdf.internal.eu.m(Unknown Source)

aspose.pdf.internal.kh.a(Unknown Source)

aspose.pdf.internal.kh.a(Unknown Source)

aspose.pdf.internal.ki.a(Unknown Source)

aspose.pdf.internal.la.a(Unknown Source)

aspose.pdf.xml.DocumentBase.a(Unknown Source)

aspose.pdf.internal.ka.a(Unknown Source)

aspose.pdf.Pdf.a(Unknown Source)

aspose.pdf.Pdf.save(Unknown Source)


Any idea what's going on? I can load images fine from a local file on my computer, but URL doesn't seem to work.

Thanks,

Chris

Hi Chris,

We are sorry for the inconvenience caused. While testing the scenario with the latest version of Aspose.Pdf for Java 4.6.0, We have managed to reproduce the reported issue and logged it in our bug tracking system as PDFNEWJAVA-34115 for further investigation and resolution. We will notify you via this thread as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,

The issues you have found earlier (filed as PDFNEWJAVA-34115) have been fixed in Aspose.Pdf for Java 9.5.2.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.