0

I have two PDF forms at the following download location - PDF Documents

These are the same file, with the only exception that version A2 was created by opening version A in Acrobat Pro DC, clicking a checkbox at the top of the form (or fill in any field), then Save As..

I'm using this code:

                PdfReader reader = new PdfReader(HttpContext.Current.Server.MapPath("~/documents/Appendix-A.pdf"));
                var form = reader.AcroFields;
                var fields = form.Fields;

When I use Appendix-A.pdf, the fields collection is properly filled. When I use Appendix-A2.pdf, the fields collection is null.

How can I get the fields and values from the filled in form (Appendix-A2.pdf)?

Note: I noticed that even the preview of the two forms at the link above is different.

Ulfius
  • 619
  • 7
  • 14
  • Looks like saving the file is changing the structure of the fields and they're going into the XfaForm property. I'm getting closer by loading the XML using. `var xform = new XfaForm(reader); var xdoc = xform.DomDocument; var new_doc = new XmlDocument(); new_doc.LoadXml(xdoc.OuterXml);` – Ulfius Aug 12 '15 at 19:47
  • I don't have time to go into this too much but your original form has Adobe usage rights enabled and when you save the PDF it does some crazy behind-the-scenes kind of things. See this for [checking for usage rights](http://stackoverflow.com/a/19382679/231316) – Chris Haas Aug 12 '15 at 19:48
  • And see [this for further discussion](http://stackoverflow.com/a/5267583/231316) – Chris Haas Aug 12 '15 at 19:48
  • I'm not going to be able to remove the usage rights because this is an external form that people will be uploading into my application. Looks like extracting the data from the XfaForm XML is going to be the route to take. – Ulfius Aug 12 '15 at 19:52

1 Answers1

1

The fields are going into the XfaForm property of the reader. All I had to do was get the XML from there and then parse to find the data fields I was after.

This post was helpful. How to get a list of the fields in an XFA form?

Data was in the <xfa:datasets><xfa:data> node.

Community
  • 1
  • 1
Ulfius
  • 619
  • 7
  • 14