Persits Software, Inc. Knowledge Base Articles

Filling Forms with Non-Flat Field Structure

Problem Description

Filling in form fields with AspPDF using the SetFieldValue method sometimes has no visible effect. This usually occurs when there are multiple form items under the same name on a form.

Solution

When there are two or more fields under the same name on a form, a PdfAnnot object returned by the Form.FindField method does not actually represent a field, but rather a "group manager" encompassing the entire group of fields sharing the same name.

Calling SetFieldValue on such a group object will have no visual effect, the fields will remain unchanged. Instead, you should iterate through the Children collection of the PdfAnnot object and call SetFieldValue on each child object individually.

' Incorrect
Set Field = Doc.Form.FindField("txtName")
Field.SetFieldValue "John Smith", Font

' Correct
Set Field = Doc.Form.FindField("txtName")
For Each Child in Field.Children
   Child.SetFieldValue "John Smith", Font
Next