Reputation: 39
I tried to get All the fields available in pdf form but I'm encountering a NullPointerException
when calling acroform.getFields()
using PDFBox.
Sample:
pdDoc = PDDocument.load(fileName);
PDAcroForm form = pdDoc.getDocumentCatalog().getAcroForm();
if(form!=null)
{
List<PDField> field = form.getFields(); //here I am getting null pointer exception
}
Upvotes: 3
Views: 5536
Reputation: 6055
I had this same error, and it turned out I was merely assuming all PDFs in our collection from this particular screen would have fields. It turned out that was not the case and that we had clients with certain pdfs that had no fields at all. So just add a null check to make sure AcroForm is not null and you should be good to go.
Upvotes: 0