Java: ImageInfo#setMemoryData leads to a NullPointerException

Hi there,



I try to set a ByteArrayOutputStream with ImageData to a PDF, but I got a NullpointerException if I want to save the pdf:



INFO: java.lang.NullPointerException

java.lang.NullPointerException

at com.aspose.pdf.elements.kb.a(Unknown Source)

at com.aspose.pdf.elements.Section.a(Unknown Source)

at com.aspose.pdf.elements.Pdf.a(Unknown Source)

at com.aspose.pdf.elements.Pdf.a(Unknown Source)

at com.aspose.pdf.elements.Pdf.save(Unknown Source)



This is the code I use:



Pdf pdf = new Pdf();



Section sec1 = pdf.getSections().add();



Text text2 = new Text(sec1, “an image from a stream\n”);

sec1.getParagraphs().add(text2);

Image img2 = new Image(sec1);

img2.getImageInfo().setMemoryData(jpegByteArrayOutputStream.toByteArray());

sec1.getParagraphs().add(img2);



pdf.save(new FileOutputStream(new File(“ImageExample.pdf”)));



The ByteArrayOutputStream has got valid image data. I’ve checked this by writing it to a file and the resuting jpeg-image looks pretty well using an Image-Viewer. Furtheron, if I pass the image to a file information the pdf is written properly:



img2.getImageInfo().setFile(“out2.jpg”);



I hope you can help.



Regards,



Christian

Hi Pinny3,

Your are right, the Aspose Pdf for Java doesn’t not support setMemoryData for Image at present. But we will soon issue a hotfix which will support setMemoryData.Thanks for your advice.