Rank: Newbie
Groups: Registered
Joined: 9/5/2019(UTC) Posts: 3 
|
There are some problems with this logic as well as with the ImportPages(..) logic which prevents copying form fields that are not flat / not top level only. 1st: ImportPages(..) does not appear to properly handle copying / updating the 'Parent' and 'Kids' references from the source document to the destination document. Using an example source document with: Code:
"AcroForm" -> "Fields" -> [
{ "DA": ..., "FT": "Tx", "Kids": [ {Kid1, Kid2}], "T": "Field1" },
{ "DA": ..., "FT": "Tx", "Kids": [ {Kid3, Kid4}], "T": "Field2" },
{ "AP": .., "DA": .., "F": .., "FT": "Tx", "MK": .., "P", .., "Rect": .., "Subtype": .., "T": "Field3", ... }
]
There are essentially 5 annotation widgets (kid1, kid2, kid3, kid4, and Field3). After calling ImportPages(..) kid1, kid2, kid3, kid4 and field3 will all be cloned and copied to the new document. But ClonedKid1.Parent, ClonedKid2.Parent, ClonedKid3.Parent, and ClonedKid4.Parent will all still point back to the original Field1 and Field2 objects which were never cloned to the new document. Additionally Field1.Kids and Field2.Kids will point to the original document Kid1, Kid2, Kid3, Kid4, not the cloned ones. In addition to the references pointing to the old document's objects, the ImportAcroForm(..) logic you provided copies the annotations to the fields array is if they're all top level. Given the above input 'fields' you would end up with a copied fields array that looks like: Code:
"AcroForm (NewDocument)" -> "Fields (NewDocument)" -> [
{ ClonedKid1 },
{ ClonedKid2 },
{ ClonedKid3 },
{ ClonedKid4 },
{ Cloned Field3 }
]
I wrote a routine to take a stab at cloning/copying the parents to the new document and ensuring the field structure is preserved. It works up until the point I attempt to save the new pdf, then the execution environment crashes with an underlying win32 exception. I'm not sure why. If I attempt to save to a file it outputs a file before crashing and the output file appears to be valid (at least valid enough that I can then re-open it as a pdf and/or inspect the fields and see that the structure was preserved). The attempt is contained in this gist: https://gist.github.com/...893a335ba99aca8cbd915822Edited by user Friday, October 18, 2019 10:27:05 AM(UTC)
| Reason: Not specified
|