Sign In  Sign Up Live-Chat

Java: ImageInfo#setMemoryData leads to a NullPointerException

Last post 04-13-2008, 10:08 PM by Sandy.Zhang. 1 replies.
Sort Posts: Previous Next
  •  04-13-2008, 7:30 AM 121974

    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
     
  •  04-13-2008, 10:08 PM 122017 in reply to 121974

    Re: Java: ImageInfo#setMemoryData leads to a NullPointerException

    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.

    Sandy.Zhang
    Product Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
View as RSS news feed in XML