Extract data from PDF form fields in Flutter
Nutrient Flutter SDK allows you to extract data from form fields programmatically. Each form field has a fully qualified name, which is used to identify and retrieve a specific form field object before extracting its data.
Obtaining the fully qualified name of a form field
The example below shows how to obtain the fully qualified name of the first form field on the first page of a document:
dynamic allAnnotations = await pspdfkitWidgetController.getAnnotations(0, 'all'); // Get the fully qualified name for the first form field. String? formFieldName = (allAnnotations[0]['formFieldName']);
Getting the data from a form field
The example below shows how to get the data from a form field with the fully qualified name, formFieldName
:
// Get the data from a form field with the fully qualified name, `formFieldName`. String? lastName = await pdfDocument.getFormFieldValue('formFieldName');
Getting form field properties
You can also get the properties of a form field using the getFormFields
method from the PdfDocument
class. This method returns a list of FormField
objects, and each field contains the most common properties for the form field. This can be useful for validating form fields and extracting additional data from them:
List<FormField> formFields = await pdfdocument.getFormFields(); for (FormField formField in formFields) { print('Field name: ${formField.name}'); print('Field readOnly: ${formField.isReadOnly}'); print('Field required: ${formField.isRequired}'); ... }