Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.4, 3.0.0 PDFBox
-
None
Description
This is related to PDFBOX-1719. The workaround made there calls PDAcroForm.setFields with an empty list when the acro form has no fields:
List<PDField> fields = acroForm.getFields(); if (fields == null) { fields = new ArrayList<PDField>(); acroForm.setFields(fields); } else { COSArray fieldArray = (COSArray) acroForm.getCOSObject().getDictionaryObject(COSName.FIELDS); fieldArray.setNeedToBeUpdated(true); }
This doesn't work anymore because PDAcroFrom.getFields never returns null in the current version, instead it returns an empty list and a NPE raises in line 295.
The source of the problem seems to be that the PDAcroForm's dictionary's COSName.FIELDS field contains null instead of an empty array. An empty array is implicitly created when calling PDAcroForm.setFields with an empty list. The PDAcroForm(PDDocument) constructor also sets an empty COSArray for the field. You could also do this in the second constrcutor, that would fix the error:
public PDAcroForm(PDDocument doc, COSDictionary form) { document = doc; dictionary = form; if (dictionary.getItem(COSName.FIELDS) == null) { dictionary.setItem(COSName.FIELDS, new COSArray()); } }
Attachments
Issue Links
- relates to
-
PDFBOX-1719 NPE while signing PDF - acroform without fields
- Closed