Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Aug 18, 2020 2:18 pm

I have a pdf that was created as an XFA document. The requirement is the user will fill out the PDF and save it, then my program will take that document, programmatically open it, loop through the form fields to get the values and insert a record into a database.

The problem is that when I load the doc, the form shows no fields. The formWidget.FieldsWidget.List.Count is 0.

Does anyone know if the spire.pdf api can handle an XFA form and if so, how do I do it?


Dim doc As New PdfDocument()
doc.LoadFromFile("C:\Forms\MyTestForm.pdf")

Dim formWidget As PdfFormWidget = TryCast(doc.Form, PdfFormWidget)

For i As Integer = 0 To formWidget.FieldsWidget.List.Count - 1

ericmcooper
 
Posts: 2
Joined: Mon Aug 17, 2020 8:48 pm

Tue Aug 18, 2020 3:34 pm

I've actually figured this out.

Dim xfaFields As List(Of XfaField) = formWidget.XFAForm.XfaFields

The only challenge now is that I need to test each for its type and cast appropriately in order to get the value. But at least now I know how to access the fields.

ericmcooper
 
Posts: 2
Joined: Mon Aug 17, 2020 8:48 pm

Wed Aug 19, 2020 8:30 am

Hello,

Glad to hear that you have found out how to get the XfaField object.
And regarding getting the value of a XfaField, you can refer to the code below. If there are any questions, just feel free to contact us.

Code: Select all
           PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"C:\Users\Test1\Desktop\1.pdf");

            //
            PdfFormWidget formWidget = doc.Form as PdfFormWidget;

            List<XfaField> xfafields = formWidget.XFAForm.XfaFields;
            foreach (XfaField xfaField in xfafields)
            {
                if (xfaField is XfaTextField)
                {
                    XfaTextField xf = xfaField as XfaTextField;
                    String value = xf.Value;
                }

            }


Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Fri Aug 28, 2020 10:00 am

Hello,

Greetings from E-iceblue.
How is your issue now? Could you please give us some feedback at your convenience?

Sincerely
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Return to Spire.PDF