Identifying form fields names
Aspose.PDF for .NET provides the capability to create, edit and fill already created Pdf forms. Aspose.Pdf.Facades namespace contains Form class, which contains the function named FillField and it takes two arguments i.e. Field name and field value. So in-order to fill the form fields, you must be aware of the exact form field name.
We often come across a scenario where we need to fill the form which is created in some tool i.e. Adobe Designer, and we are not sure about the form fields names. So in order to fill the form fields, first we need to read the names of all the Pdf form fields. Form class provides the property named FieldNames which returns the entire field’s names and returns null if PDF does not contain any field. However, when using this property, we get the names of the entire field’s in PDF form and we might not be certain that which name corresponds to which field over the form.
As a solution to this problem, we will use the appearance attributes of each field. Form class has a function named GetFieldFacade which returns attributes, including location, color, border style, font, list item and so on. To save these values we need to use FormFieldFacade class, which is used to record visual attributes of the fields. Once we have these attributes we can add a text field beneath every field which would be displaying the field name.
In Aspose.Pdf.Facades namespace we have a class named FormEditor which provides the capability to manipulate PDF forms. Open a pdf form; add a text field beneath every existing form field and save the Pdf form with new name.