NullPointerException in the Form.importXml (First Time Only)

Hi there,

Aspose pdf version - aspose-pdf-10.3.0.jar

Platform – Fuse Windows, Fuse Linux

We filling Fillable PDFs use the following code in a camel route.

The license is initialized as part of the spring bean afterPropertiesSet() method.

Document pdf = new Document(pdftemplateName);

Form form = new Form();

form.bindPdf(pdf);

//import the changes to the pdf from xml stream

InputStream xmlInputStream = xml input stream

form.importXml(xmlInputStream);

xmlInputStream.close();

ByteArrayOutputStream bObj = new ByteArrayOutputStream();

form.save(bObj);

byte[] byteArray = bObj.toByteArray();

The first time this code get executed we get the following null pointer exception. Successive runs of this method works for the same input xml.

java.lang.NullPointerException

at com.aspose.pdf.internal.p359.z32.m1(Unknown Source)

at com.aspose.pdf.internal.p361.z2.m1(Unknown Source)

at com.aspose.pdf.internal.p575.z11.m4(Unknown Source)

at com.aspose.pdf.internal.p575.z11.m7(Unknown Source)

at com.aspose.pdf.internal.p575.z11.m3(Unknown Source)

at com.aspose.pdf.internal.p575.z8.m1(Unknown Source)

at com.aspose.pdf.internal.p576.z12.m4(Unknown Source)

at com.aspose.pdf.internal.p576.z7.(Unknown Source)

at com.aspose.pdf.internal.p576.z9.(Unknown Source)

at com.aspose.pdf.internal.p576.z12.(Unknown Source)

at com.aspose.pdf.internal.p575.z8.m1(Unknown Source)

at com.aspose.pdf.internal.p578.z27.m28(Unknown Source)

at com.aspose.pdf.internal.p578.z27.m1(Unknown Source)

at com.aspose.pdf.internal.p578.z29.m1(Unknown Source)

at com.aspose.pdf.internal.p578.z27.m1(Unknown Source)

at com.aspose.pdf.internal.p580.z1.m1(Unknown Source)

at com.aspose.pdf.internal.p579.z4.m1(Unknown Source)

at com.aspose.pdf.internal.p580.z1.m1(Unknown Source)

at com.aspose.pdf.internal.p580.z1.m2(Unknown Source)

at com.aspose.pdf.TextBoxField.m2(Unknown Source)

at com.aspose.pdf.WidgetAnnotation.m1(Unknown Source)

at com.aspose.pdf.Field.updateAppearances(Unknown Source)

at com.aspose.pdf.Field.m6(Unknown Source)

at com.aspose.pdf.Field.setValue(Unknown Source)

at com.aspose.pdf.TextBoxField.setValue(Unknown Source)

at com.aspose.pdf.facades.AForm.m2(Unknown Source)

at com.aspose.pdf.facades.AForm.importXml(Unknown Source)

at com.aspose.pdf.facades.Form.importXml(Unknown Source)


Input xml:

<?xml version="1.0" encoding="UTF-8"?>

<fields xmlns:docfun="http://wwww.connecture.com/integration/docgen"
xmlns:dyn="http://exslt.org/dynamic" xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:gsp="http://groovy.codehaus.org/2005/gsp">
<field name="Applicant_Signature">
PrimaryFName, PrimaryLName



Thanks.

Hi Chamal,


Thanks for your inquiry. We will appreciate it if you please share your sample PDF document as well here. So we will look into it and guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Sample PDF attached. I did change to another pdf and the same error in the first call of the method.


Hi Chamal,


Thanks for sharing the resource files.

I have tested the scenario while using following code snippet in Eclipse Juno project with JDK 1.7 where I have used Aspose.Pdf for Java 10.4.1 and I am unable to notice any issue while filling PDF form. I have tried filling the form in multiple attempts but error appears.

However now we are working on testing the scenario over Linux platform and will keep you posted with our findings.

[Java]

Document pdf = new Document(“c:/pdftest/CHE-COCR(7_13)V1.0.pdf”);<o:p></o:p>

com.aspose.pdf.facades.Form form = new com.aspose.pdf.facades.Form();

form.bindPdf(pdf);

//import the changes to the pdf from xml stream

InputStream xmlInputStream = new java.io.FileInputStream("c:/pdftest/CHE-COCR(7_13)V1.0_data.xml"); // = xml input stream

//form.importXml("c:/pdftest/CHE-COCR(7_13)V1.0_data.xml");

form.importXml(xmlInputStream);

form.save("c:/pdftest/CHE-COCR(7_13)_Filled.pdf");

xmlInputStream.close();

It has the same behavior on Windows and Linux. It fails the first time through and works in successive invocations in the Fuse container.






Hi Chamal,


Thanks for sharing the feedback.

As per your above statement, the problem appears over both Windows as well as Linux but I am afraid I am unable to replicate it over Windows. Can you please share some further details which can help us in reproducing the issue in our environment.

May be it has something to do with Fuse Container. Can you please share some details on steps to configure the environment.