Free Support Forum -

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


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 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”);


Image img2 = new Image(sec1);


sec1.getParagraphs().add(img2); 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:


I hope you can help.



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.