Back to Devexpress

PdfAcroFormTextBoxField Class

officefileapi-devexpress-dot-pdf-2cf5fe95.md

latest6.6 KB
Original Source

PdfAcroFormTextBoxField Class

A text box form field.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Pdf.v25.2.Core.dll

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public class PdfAcroFormTextBoxField :
    PdfAcroFormCommonVisualField
vb
Public Class PdfAcroFormTextBoxField
    Inherits PdfAcroFormCommonVisualField

The following members return PdfAcroFormTextBoxField objects:

Remarks

Create a Text Box Form Field

To create a text box field, call the PdfAcroFormField.CreateTextBox method with the specified the field name, page number where the field will be added, and field rectangle in user coordinate system.

You can also create a new PdfAcroFormTextBoxField object and pass all parameters mentioned above to the object constructor.

To add text box fields to a document, pass an array of PdfAcroFormTextBoxField objects as a parameter to the PdfDocumentProcessor.AddFormFields method.

Specify Form Field Settings

Use members of the PdfAcroFormTextBoxField class to specify the text box field properties. For example, you can specify the text box text, and type using PdfAcroFormTextBoxField.Text and PdfAcroFormTextBoxField.Type properties.

To specify the text box name, tooltip and appearance, use the PdfAcroFormField.Name, PdfAcroFormField.ToolTip, and PdfAcroFormVisualField.Appearance properties.

Remove Text Box Form Fields

To delete a form field from a document using a field name, call the PdfDocumentProcessor.RemoveFormField method.

To delete all interactive elements from a document, call the PdfDocumentProcessor.RemoveForm method.

Example

This example creates a text box and radio button group fields, and adds them to a document.

View Example

csharp
using DevExpress.Pdf;

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document:
    processor.LoadDocument("..\\..\\Document.pdf");

    // Create a text box field:
    PdfAcroFormTextBoxField textBox =
         new PdfAcroFormTextBoxField("text box", 1, new PdfRectangle(230, 690, 280, 710));

    // Specify text box text and appearance:
    textBox.Text = "Text Box";
    textBox.Appearance.BackgroundColor = new PdfRGBColor(0.8, 0.5, 0.3);
    textBox.Appearance.FontSize = 12;

    // Create a radio group field:
    PdfAcroFormRadioGroupField radioGroup =
         PdfAcroFormField.CreateRadioGroup("Gender Group", 1);

    // Add the first radio button to the group and specify its location:
    radioGroup.AddButton("button1", new PdfRectangle(230, 635, 250, 655));

    // Add the second radio button to the group:
    radioGroup.AddButton("button2", new PdfRectangle(310, 635, 330, 655));

    // Specify radio group's selected index and appearance:
    radioGroup.SelectedIndex = 0;
    radioGroup.Appearance.BorderAppearance = new PdfAcroFormBorderAppearance()
    { Color = new PdfRGBColor(0.8, 0.5, 0.3), Width = 3 };

    // Add form fields to the page:
    processor.AddFormFields(textBox, radioGroup);

    // Save the resulting document:
    processor.SaveDocument("..\\..\\Result.pdf");
}
vb
Imports DevExpress.Pdf

Namespace AddFormFieldsToExistingDocument
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            Using processor As New PdfDocumentProcessor()

                ' Load a document:
                processor.LoadDocument("..\..\Document.pdf")

                ' Create a text box field:
                Dim textBox As New PdfAcroFormTextBoxField("text box", 1, New PdfRectangle(230, 690, 280, 710))

                ' Specify text box text and appearance:
                textBox.Text = "Text Box"
                textBox.Appearance.BackgroundColor = New PdfRGBColor(0.8, 0.5, 0.3)
                textBox.Appearance.FontSize = 12

                ' Create a radio group field:
                Dim radioGroup As PdfAcroFormRadioGroupField = PdfAcroFormField.CreateRadioGroup("Gender Group", 1)

                ' Add the first radio button to the group and specify its location:
                radioGroup.AddButton("button1", New PdfRectangle(230, 635, 250, 655))

                ' Add the second radio button to the group:
                radioGroup.AddButton("button2", New PdfRectangle(310, 635, 330, 655))

                ' Specify radio group selected index and appearance:
                radioGroup.SelectedIndex = 0
                radioGroup.Appearance.BorderAppearance = New PdfAcroFormBorderAppearance() With {.Color = New PdfRGBColor(0.8, 0.5, 0.3), .Width = 3}

                ' Add form fields to the page:
                processor.AddFormFields(textBox, radioGroup)

                ' Save the resulting document:
                processor.SaveDocument("..\..\Result.pdf")
            End Using
        End Sub
    End Class
End Namespace

Inheritance

Object PdfAcroFormField PdfAcroFormVisualField PdfAcroFormCommonVisualField PdfAcroFormTextBoxField

See Also

PdfAcroFormTextBoxField Members

DevExpress.Pdf Namespace