Fill Interactive Forms
- 3 minutes to read
This document describes how to fill a document with interactive forms and provides customization options.
PDF Viewer allows you to enter or select values in fillable form fields.
Customization
Highlight Form Field
The PDF Viewer can highlight interactive form fields with a color. To enable this functionality, set the PdfViewerControl.HighlightFormFields property to true.
If you wish to change the default color, which is used to highlight form fields, use the PdfViewerControl.HighlightedFormFieldColor property.
The image below demonstrates the PdfViewerControl.HighlightedFormFieldColor property set to Color.FromArgb(120, 255, 0, 0).
Change Form Field Value
You can use the PdfDocumentFacade class to specify form field values.
Important
The Universal Subscription or an additional Office File API Subscription is required to use this example in production code. Refer to the DevExpress Subscription page for pricing information.
The PdfViewerExtensions.GetDocumentFacade(IPdfViewer) method retrieves the PdfDocumentFacade class object that allows you to change the PDF document without access to its inner structure. Use the PdfDocumentFacade.AcroForm property to get interactive form field options.
Each FormFieldFacade class has the Value property that allows you to specify a form field value. Use the PdfChoiceFormFieldFacade.Items property to obtain a list of choice form field (combo box, list box) values.
The code sample below specifies various form field values:
public MainWindow()
{
InitializeComponent();
pdfViewer.DocumentLoaded += PdfViewer_DocumentLoaded;
pdfViewer.OpenDocument("FormDemo.pdf");
}
private void PdfViewer_DocumentLoaded(object sender, RoutedEventArgs e)
{
pdfViewer.DocumentLoaded -= PdfViewer_DocumentLoaded;
FillFormFields();
}
private static void FillFormFields()
{
PdfDocumentFacade documentFacade = pdfViewer.GetDocumentFacade();
PdfAcroFormFacade acroForm = documentFacade.AcroForm;
PdfTextFormFieldFacade visaField = acroForm.GetTextFormField("VisaNo");
visaField.Value = "73203393";
PdfTextFormFieldFacade addressField = acroForm.GetTextFormField("Address");
addressField.Value = "98033, 722 Moss Bay Blvd., Kirkland, WA, USA";
PdfRadioGroupFormFieldFacade genderField = acroForm.GetRadioGroupFormField("Gender");
genderField.Value = genderField.Field.Items[2].Value;
PdfComboBoxFormFieldFacade nationalityField = acroForm.GetComboBoxFormField("Nationality");
nationalityField.Value = nationalityField.Items[68].Value;
pdfViewer.SaveDocument("FormDemo_new.pdf");
}
Form Field Events
Handle one the following events to control specific form field actions:
Event | Description |
---|---|
FormFieldValueChanging | Occurs when the user starts to edit a form field value. |
FormFieldValueChanged | Fires after a form field value is changed. |
PdfViewerControl.ShowingEditor | Fires when the form field receives focus. |
PdfViewerControl.HiddenEditor | Occurs when the form field loses focus. |