Skip to main content
A newer version of this page is available. .

How to: Fill an Interactive Form with Values

  • 3 minutes to read

Important

You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use these examples in production code. Refer to the DevExpress Subscription page for pricing information.

The example shows how to fill an existing interactive form using field names.

To obtain interactive form data, call the PdfDocumentProcessor.GetFormData method. Then, specify a value for a form field using the PdfFormData.Value property.

To obtain the names of the interactive form fields, use the PdfDocumentProcessor.GetFormFieldNames method.

To apply data to the interactive form, call the PdfDocumentProcessor.ApplyFormData method.

To learn how to get a checked appearance name for the check box, see the How to: Obtain a Checked Appearance Name for a Check Box example.

To learn how to get a checked appearance name for the radio button, see the How to: Obtain a Checked Appearance Name for Each Radio Button in the Radio Group example.

// Load a document with an interactive form.
using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) {
    documentProcessor.LoadDocument(filePath + fileName + ".pdf");

    // Obtain interactive form data from a document.
    PdfFormData formData = documentProcessor.GetFormData();

    // Specify the value for FirstName and LastName text boxes.
    formData["FirstName"].Value = "Janet";
    formData["LastName"].Value = "Leverling";

    // Specify the value for the Gender radio group.
    formData["Gender"].Value = "Female";

    // Specify the check box checked appearance name.
    formData["Check"].Value = "Yes";

    // Specify values for the Category list box.
    formData["Category"].Value = new string[] { "Entertainment", "Meals", "Morale" };

    // Obtain data from the Address form field and specify values for Address child form fields.
    PdfFormData address = formData["Address"];

    // Specify the value for the Country combo box. 
    address["Country"].Value = "United States";

    // Specify the value for City and Address text boxes. 
    address["City"].Value = "California";
    address["Address"].Value = "20 Maple Avenue";

    // Apply data to the interactive form. 
    documentProcessor.ApplyFormData(formData);

    // Save the modified document.
    documentProcessor.SaveDocument(filePath + fileName + "_new.pdf");

    btnFillFormData.Enabled = false;
    btnLoadFilledPDF.Enabled = true;
}