Don't store complex data in PDFDocument.formInfo
, and replace the fields
object with a hasFields
boolean instead
#12483
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch is based on a couple of smaller things that I noticed when working on PR #12479.
Don't store the /Fields on the
formInfo
getter, since that feels like overloading it with unintended (and too complex) data, and utilize ahasFields
boolean instead.This functionality was originally added in PR Improve AcroForm/XFA form type detection #12271, to help determine what kind of form data a PDF document contains, and I think that we should ensure that the return value of
formInfo
only consists of "simple" data.With these changes the
fieldObjects
getter instead has to look-up the /Fields manually, however that shouldn't be a problem since the access is guarded by aformInfo.hasFields
check which ensures that the data both exists and is valid. Furthermore, most documents doesn't even have any /AcroForm data anyway.Determine the
hasFields
property first, to ensure that it's always correct even if there's errors when checking e.g. the /XFA or /SigFlags entires, since thefieldObjects
getter depends on it.Simplify a loop in
fieldObjects
, since the object being accessed is aMap
and those have built-in iteration support.Use a higher logging level for errors in the
formInfo
getter, and include the actual error message, since that'd have helped with fixing PR Fix the "should get form info when AcroForm is present" unit-test #12479 a lot quicker.Update the JSDoc comment in
src/display/api.js
to list the return values correctly, and also slightly extend/improve the description.