Filling out a Static XFA PDF using iText

348 views Asked by At

I have a Static XFA PDF, that I wish to programmatically fill out. I can use the Xfa.FillXfaForm() method and this works well to update the XFA Dataset DOM. However, it does not update the corresponding Acroform field annotations (A Static XFA form has both an XFA form and an Acroform inside it). An XFA compliant renderer will pick up and read the XML Dataset Dom, however, many renderers such as Google Chrome and Firefox ignore the XFA dictionary, which means the form does not appear filled out there. Is there a way for iText to sync the Acroform and XFA values parts of the static form? I am using iTextSharp 5.

1

There are 1 answers

0
joelgeraci On

My answer and best advice would be... Don't!

If you're using Static XFA and your main concern is to have it display consistently in non-Adobe viewers and you have access to a decent library tool like iText, you're really better off stripping the XFA dictionary out of the PDF and just dealing with the AcroForm fields. Once you've got non-XFA aware and XFA aware viewers touching the PDF, deciding which set of data is the right set is problematic and field values vs. appearances can get out of sync. Any FormCalc scripts and expanding fields wouldn't be handled properly by the non-XFA viewers so there's really no advantage to having the XFA portion around at all.

During this process, you could build a map between the XML input and the AcroForm field names and store that in the document metadata so your application can easily populate the form as though it were still XFA but you wouldn't need to worry about synchronizing the data with two completely different and incompatible forms technologies in the same PDF. (Honestly, I'd love to know who thought that was a good idea in the first place)