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

Free Support Forum - aspose.com

Null pointer exception flattening a form

Hello, I am getting the following exception when attempting to flatten the attached file


java.lang.NullPointerException: null
at com.aspose.pdf.Page.m1(Unknown Source) ~[aspose-pdf-11.0.0.jar:11.0.0]
at com.aspose.pdf.Page.m2(Unknown Source) ~[aspose-pdf-11.0.0.jar:11.0.0]
at com.aspose.pdf.ADocument.m9(Unknown Source) ~[aspose-pdf-11.0.0.jar:11.0.0]
at com.aspose.pdf.ADocument.flatten(Unknown Source) ~[aspose-pdf-11.0.0.jar:11.0.0]
at com.aspose.pdf.Document.flatten(Unknown Source) ~[aspose-pdf-11.0.0.jar:11.0.0]
at com.aspose.pdf.facades.AForm.flattenAllFields(Unknown Source) ~[aspose-pdf-11.0.0.jar:11.0.0]
at com.aspose.pdf.facades.Form.flattenAllFields(Unknown Source) ~[aspose-pdf-11.0.0.jar:11.0.0]
at gov.grantsolutions.documentprocessor.conversion.PDFConverter.convertToPdf(PDFConverter.java:71) ~[classes/:na]


I am using the Facades as recommended:

Form form = new Form();
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(sourcepath.toString());
form.bindPdf(pdfDocument);
form.flattenAllFields();

I am using the latest version 11.0.0 for Java

Hi Erich,


Thanks for your inquiry. Your shared PDF document does not contain any form field so you are getting the exception. You may amend your code as following, it will help you to avoid the exception.

Form form = new Form();

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("C1c6d709f-150e-42fb-937c-7f9be010f3e2.pdf");

form.bindPdf(pdfDocument);

String[] fields = form.getFieldNames();

if (fields.length!=0)

form.flattenAllFields();

else

System.out.println("No form field found");


Please feel free to contact us for any further assistance.


Bet Regards,

I’d already implemented this as a workaround, but the library should probably be handling this itself. Also, FYI, I have ‘formless’ documents for which this doesn’t happen as well.

Hi Erich,

Thanks for your feedback.

eoliphantgs:
I'd already implemented this as a workaround, but the library should probably be handling this itself.

We have logged an enhancement ticket PDFNEWJAVA-35386 to handle the exception a Aspose.Pdf end. We will keep you updated about the issue resolution progress.


eoliphantgs:
Also, FYI, I have 'formless' documents for which this doesn't happen as well.

We will appreciate it if you please share some sample PDF "formless" document that does not throw the exception, we will look into it and provide you information accordingly.

We are sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNEWJAVA-35386) have been fixed in Aspose.Pdf for Java 11.1.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.