Fill Interactive Forms

  • 2 minutes to read

This document describes how to fill a document with interactive forms and customize form field behavior.

Overview

PDF Viewer allows you to enter or select values in fillable form fields.

InteractiveForm

Customization

Highlight Form Fields

The PDF Viewer can highlight interactive form fields with a color. To enable this functionality, set the PdfViewer.HighlightFormFields property to true.

If you wish to change the default color, which is used to highlight form fields, use the PdfViewer.HighlightedFormFieldColor property.

The image below shows a form field highlighted with a red color.

HighlightFormFieldColor_Red

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:

PdfDocumentFacade documentFacade = pdfViewer.GetDocumentFacade();
PdfAcroFormFacade acroForm = documentFacade.AcroForm;
FillFormFields(acroForm);
pdfViewer.SaveDocument();

private static void FillFormFields(PdfAcroFormFacade 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;
}

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.
FormFieldGotFocus Fires when the form field receives focus.
FormFieldLostFocus Occurs when the form field loses focus.