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

Free Support Forum - aspose.com

Exception while modifying/save existing pdf after image addition to pdfdocument

Hi,

We are using aspose.pdf(ver 10.2.0 ) for adding an image to the existing pdf.

Its not giving any error while adding the image to the pdf but when i try to save the modified pdf it gave me null point error as shown below trace.

Line# 191 pdfDocument.save(pdfGenFilePath);//here it gives error
below line is for setting the image inputstream.
image.setImageStream(inputImg);//here inputImg path is not correct or file doesnt exist

How to handle this scenario, expecting it has to warn while adding empty/corrupted image instead of during save the pdf file.

Please suggest a workaround.

=================ERROR==================
java.lang.NullPointerException
at com.aspose.pdf.Image.m1(Unknown Source)
at com.aspose.pdf.Image.m1(Unknown Source)
at com.aspose.pdf.z59.m5(Unknown Source)
at com.aspose.pdf.Cell.m1(Unknown Source)
at com.aspose.pdf.Row.m1(Unknown Source)
at com.aspose.pdf.Row.m1(Unknown Source)
at com.aspose.pdf.Table.m1(Unknown Source)
at com.aspose.pdf.z59.m5(Unknown Source)
at com.aspose.pdf.Page.m2(Unknown Source)
at com.aspose.pdf.Page.processParagraphs(Unknown Source)
at com.aspose.pdf.ADocument.processParagraphs(Unknown Source)
at com.aspose.pdf.Document.processParagraphs(Unknown Source)
at com.aspose.pdf.ADocument.saveInternal(Unknown Source)
at com.aspose.pdf.Document.saveInternal(Unknown Source)
at com.aspose.pdf.ADocument.save(Unknown Source)
at com.aspose.pdf.Document.save(Unknown Source)
at my.pdf.utility.PDFGenerator.generatePDF(PDFGenerator.java:191)
at my.pdf.utility.PDFGenerator.main(PDFGenerator.java:274)
Process exited with exit code 0.

Hi Hana,


Thanks for using our API’s.

Can you please share the resource PDF document and code snippet which you are using, so that we can test the scenario in our environment. We are sorry for this inconvenience.

This issue is not happening in all the time, only few cases, assuming that the image addition/loading is not correct hence it throws error while saving the updated pdf document.

I have already added the snippet in my description of the issue.

Please let me know if you still need more details.

Thanks.

Hi Hana,


Thanks for sharing the details.

Are you facing issue while manipulating any specific document or its occurring for all the documents ? Also please share if its happening for any specific image or its occurring for most of the image files.

I am afraid in order for us to fix this problem, first we need to replicate it in our environment so that we can figure out the actual reasons behind it. Furthermore, from your description, it appears to be an intermittent issue and not easy to reproduce. Anyways, please share some details regarding your working environment i.e. Operating System, JDK version etc.

We are really sorry for this inconvenience.

Hi,

We are facing this issue intermittently, and not always with same place or same document.

I feel, when it try to add one image, if that image is taking bit delay reading from filesystem, then aspose is not adding properly, when we save that document then its failing with said exception.

As its api trace, we are not able to identify exactly what it is trying and failed.

when we try the same document, same scenario it works.

If you required, more details of trace I can share, but as its not specific to a document or an image, i could not provide the source.

We are running the application on Linux machines, and jdk version we used is jdk1.7.0_85.

Please let me know if more details required.

Thanks.

Hi Hana,


Thanks for sharing the details.

Many of our customers are using Aspose.Pdf for Java on Linux platform and the API is working fine. However this problem might be related to access privileges when trying to load the source/input image or some delay in IO.

As shared earlier, in order to resolve the problem, we need to first replicate it in our environment and then try figuring out the actual reasons behind this problem. So please share some sample files which can help us in reproducing the issue in our environment. I have also observed that you are using an older release of Aspose.Pdf for Java and in recent release versions, we have made many improvements while creating as well as manipulating existing PDF files, so we suggest you to please try using latest release of Aspose.Pdf for Java 11.1.0 and see if it resolves your problem.