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

Free Support Forum - aspose.com

PDF generation with image from inputstream


I use aspose.pdf for Java 2.9.0 and run it in Tomcat environment. I try to insert an image to pdf but get the following error (got the extended stack trace using the hot fix 3.0.5). I want to access the resource from an archive that’s why I have to work with getResourceAsStream() function.

Couldn’t convert image stream:
java.lang.RuntimeException: offset is too larger
at aspose.pdf.BinaryFileStream.read(SourceFile:424)
at aspose.pdf.MemStream.(SourceFile:101)
at aspose.pdf.BinaryFileStream.toMemStream(SourceFile:621)
at aspose.pdf.figure.Abi.a(SourceFile:94)
at aspose.pdf.figure.Aba.a(SourceFile:163)
at aspose.pdf.figure.Aba.a(SourceFile:97)
at aspose.pdf.xml.Abh.a(SourceFile:227)
at aspose.pdf.xml.Abh.a(SourceFile:633)
at aspose.pdf.xml.Abi.a(SourceFile:578)
at aspose.pdf.xml.Acc.a(SourceFile:799)
at aspose.pdf.xml.Aar.a(SourceFile:104)
at aspose.pdf.xml.Aba.a(SourceFile:113)
at aspose.pdf.Pdf.save(SourceFile:1167)
at aspose.pdf.Pdf.save(SourceFile:1113)

I thought of transforming the InputStream to BinaryFileStream - is this approach correct in general? I can’t use the alternative setImageStream function, because it’s restricted to FileInputStreams…

InputStream is = this.getClass().getResourceAsStream(“logo.png”);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryFileStream bfs = new BinaryFileStream(baos.toByteArray());
Image img = new Image();

hope you can help me,

kind regards

Hi Andreas,

Thanks for using our products.

Can you please share the source image file so that we can test the scenario at our end. We apologize for your inconvenience.


here’s the image as an example. I’ve tested various image types and all were resulting in the same exception.

Hi Andreas,

Thanks for sharing the resource file. We are working over this query and will get back to you soon. We are sorry for the delay and inconvenience.

Hi Andreas,

Thanks for your patience and sorry for the long delay. In order to accomplish your requirement, you may try using the following code to read the source image and place it inside PDF file.

Pdf pdf = new Pdf();
Section sec = pdf.getSections().add();
// Read from an input stream
InputStream is = new BufferedInputStream(new FileInputStream(“d:/pdftest/java-logo.png”));

BufferedImage image = ImageIO.read(is);
Image img = new Image();

In case you still face any issue or you have any further query, please feel free to contact. We are sorry for your inconvenience.


thanks for your help, I really appreciate it - it’s working now…

kind regards,


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

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan