Skip to main content
.NET Framework 4.5.2+

PdfGraphics.AddFormField(PdfGraphicsAcroFormField) Method

Adds an interactive form field as graphics content.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v22.1.Drawing.dll

Declaration

public void AddFormField(
    PdfGraphicsAcroFormField field
)

Parameters

Name Type Description
field PdfGraphicsAcroFormField

An interactive form field that should be added.

Remarks

To access the PdfGraphics class, you need to reference the DevExpress.Pdf.Drawing.v22.1 assembly.

The table below lists available form fields and API used to create each type. All methods and class constructors from the table operate in the world coordinate system.

Form Field Class Method
Check Box PdfGraphicsAcroFormCheckBoxField No method
Combo Box PdfGraphicsAcroFormComboBoxField PdfGraphicsAcroFormField.CreateComboBox
List Box PdfGraphicsAcroFormListBoxField PdfGraphicsAcroFormField.CreateListBox
Radio Group PdfGraphicsAcroFormRadioGroupField PdfGraphicsAcroFormField.CreateRadioGroup
Signature PdfGraphicsAcroFormSignatureField PdfGraphicsAcroFormField.CreateSignature
Text Box PdfGraphicsAcroFormTextBoxField PdfGraphicsAcroFormField.CreateTextBox

To add an interactive field to a page, call one of the following methods:

PdfGraphics.AddToPageForeground, PdfGraphics.AddToPageBackground
These methods allow you to draw content on an existing page.
PdfDocumentProcessor.RenderNewPage
Draws content on a new page.

Tip

You can use the PdfAcroFormField class to add interactive form fields to a PDF file. Refer to the following article for more information: Interactive Forms in PDF Documents

Example

This example shows how to use PDF Graphics API to add interactive form fields – text box and radio button group.

View Example

using DevExpress.Pdf;
using System.Drawing;

using (var processor = new PdfDocumentProcessor()) {
    // Create an empty document.
    processor.CreateEmptyDocument("..\\..\\Result.pdf");

    // Create graphics and draw form fields.
    using (PdfGraphics graphics = processor.CreateGraphics()) {
        DrawFormFields(graphics);

        // Render a page with graphics.
        processor.RenderNewPage(PdfPaperSize.Letter, graphics);
    }
}


static void DrawFormFields(PdfGraphics graphics){
    // Create a text box field and specify its location on the page.
    var textBox =
         new PdfGraphicsAcroFormTextBoxField("text box", new RectangleF(30, 10, 200, 30));

    // Specify text and appearance parameters.
    textBox.Text = "Text Box";
    textBox.Appearance.FontSize = 12;
    textBox.Appearance.BackgroundColor = Color.AliceBlue;

    // Add the text box field to graphics.
    graphics.AddFormField(textBox);

    // Create a radio group field.
    var radioGroup =
         new PdfGraphicsAcroFormRadioGroupField("First Group");

    // Add the first radio button to the group and specify its location.
    radioGroup.AddButton("button1", new RectangleF(30, 60, 20, 20));

    // Add the second radio button to the group.
    radioGroup.AddButton("button2", new RectangleF(30, 90, 20, 20));

    // Specify radio group selected index
    radioGroup.SelectedIndex = 0;

    // Specify appearance options:
    radioGroup.Appearance.BorderAppearance =
         new PdfGraphicsAcroFormBorderAppearance()
        {
            Color = Color.Red,
            Width = 3
        };

    // Add the radio group field to graphics.
    graphics.AddFormField(radioGroup);
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the AddFormField(PdfGraphicsAcroFormField) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also