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

Free Support Forum - aspose.com

NullPointerException with XFA.getFieldNames()

Aspose-pdf-9.5.2


I am experiencing an issue when trying to read a Static PDF(PDF Version: 1.7(Acrobat XI)), with form field data populated, with the following code:

Document someDocument = new com.aspose.pdf.Document(“StaicWithData.pdf”);
XFA someForm = someDocument.getForm().getXFA();
String[] fields = someForm.getFieldNames();

The call to getFieldNames() results in:

java.lang.NullPointerException
at com.aspose.pdf.internal.p474.z1.m1(Unknown Source)
at com.aspose.pdf.internal.p474.z1.m7(Unknown Source)
at com.aspose.pdf.XFA.getFieldNames(Unknown Source)

I can confirm that someDocument and someForm are not null. While I understand this code isn’t 100% necessary to process the Static form, it is used within a utility method to determine the overall PDF type and the strategy we use internally to process the form and field values. This internal null pointer being generated is unexpected in any case.

Also of note here is the same code works just fine if there is no fields populated within the document. I will attach both examples of the static form, with and without the data. Thank you.

Hi Brian,

Thanks for your inquiry. While testing the scenario with your shared document, we have managed to reproduce the issue with latest version of Aspose.Pdf for Java 9.5.2. We have logged a ticket PDFNEWJAVA-34559 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,

Hi Brian,


Moreover you can check Form type as following and implement your logic accordingly. Hopefully it will help you to accomplish the task.

Document pdf = new Document(myDir + “Dynamic_filled.pdf”);<o:p></o:p>

if (pdf.getForm().getType()==FormType.Dynamic)

{

String[] fields = pdf.getForm().get_xfa().getFieldNames();

for (int i = 0; i < fields.length; i++) {

System.out.println("XFA form field: " + fields[i]);

}

}

else

{

Field[] fields1 = pdf.getForm().getFields();

for (int i = 0; i < fields1.length; i++) {

System.out.println("Form field: " + fields1[i].getPartialName());

}

}

Best Regards,