I am trying to fill out this PDF form programmatically with PDFBox 2:
https://www.shadowrunsixthworld.com/wp-content/uploads/SR6-Character-Sheet-Fillable.pdf
When I look at it with the PDF Debugger, I see different fields than if I
look at it using the PDFBox API. For instance:
PDF Debugger:
Page 1 has 89 annotations, all Widgets as far as I can tell
The first two are #127, unnamed, child of #2185 ("Body"), and #128 named
"Essence"
Page 2 has 42 annotations, all Widgets as far as I can tell
Interestingly, one on this page is #2052, also unnamed, and ALSO a child of
#2185 ("Body"). Thus there are two fields in the human-readable document
named "Body" (one on each page), and it looks like that's represented in
the annotations by two different unnamed annotations on the two pages that
are both children of the same parent object (2185), which is named "Body".
If I load the PDDocument.PDDocumentCatalog.AcroForm:
If I getFields, it returns 109 -- which doesn't match the PDFDebugger total
of 89+42
If I getFieldIterator, it iterates 135, also not 89+42 and also not 109
Only one of the fields in either case is named "Body" -- it seems like
these are indexed by name somehow such that the second unnamed child of
2185 replaces the first (e.g. I see only #2052 not #127).
So again, the first field listed by either of those calls is Essence
(#128). They appear to skip #127, which is one of the "Body" children.
(If I open this PDF in a regular PDF viewer, I can put an entry into what I
believe is that field, so it's not like it doesn't exist.)
Here's what I want: to fill out most all of the fields in this document
that are not check boxes, INCLUDING #127 (the missing first "Body" child).
Because the names are a mess I'd be OK doing it by object ID not by name
(effectively, set annotation #127 to contain "foo", set #128 to contain
"bar", etc.)
Is that possible with PDFBox 2.0.23 and this source PDF? Essentially, I
want to get the same list of fields that the PDF Debugger shows under
"Annotations" for each page and then provide values for most of those and
save the document.
I see I can go to PDDocument.PDPage.getAnnotations, but I don't see how to
get from a PDAnnotation to a PDField in order to write the new value to the
field. Would it work to setContents on that annotation and just ignore the
AcroForm and PDField objects? What's the effective difference between
annotation contents and field value?
Thanks,
Aaron