Back to Devexpress

PdfGraphicsAcroFormChoiceField Class

officefileapi-devexpress-dot-pdf-aaa55f27.md

latest7.3 KB
Original Source

PdfGraphicsAcroFormChoiceField Class

A base class for combo box and list box fields in PDF Graphics API.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Drawing

Declaration

csharp
public abstract class PdfGraphicsAcroFormChoiceField :
    PdfGraphicsAcroFormCommonField
vb
Public MustInherit Class PdfGraphicsAcroFormChoiceField
    Inherits PdfGraphicsAcroFormCommonField

Remarks

To access the PdfGraphicsAcroFormChoiceField class descendants, you need to reference the DevExpress.Pdf.Drawing.v25.2 assembly.

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

Create a Form Field

To create a combo box or a list box field, create a new PdfGraphicsAcroFormComboBoxField or PdfGraphicsAcroFormListBoxField object, and pass the field name and location as constructor parameters. You can also call the PdfGraphicsAcroFormField.CreateComboBox or PdfGraphicsAcroFormField.CreateListBox method to create a combo box or a list box field.

Use the AddValue method to add items to the combo box or list box fields. The ClearValues() method call clears all form field items.

Specify Form Field Parameters

The following parameters are available:

ParameterAPI
Form field nameName
Tooltip textToolTip
Selected item (by index)SetSelected(Int32, Boolean)
Selected item (by export value)SelectValue(String)
Appearance settings (background and foreground color, font and border options)Appearance

Add a Form Field as Graphics Content

To add a combo box or a list box field as graphics content, pass a PdfGraphicsAcroFormComboBoxField or PdfGraphicsAcroFormListBoxField object as a parameter to the PdfGraphics.AddFormField method.

Draw a Form Field on a Page

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

Example

This example uses PDF Graphics API to create a combo box field and add it to a PDF page.

View Example

csharp
using DevExpress.Pdf;
using System.Drawing;
//...

static void Main(string[] args)
{
    using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
    {
        // Create an empty document.
        processor.CreateEmptyDocument("..\\..\\Result.pdf");

        // Create graphics and draw a combo box field.
        using (PdfGraphics graphics = processor.CreateGraphicsPageSystem())
        {
            DrawComboBoxField(graphics);

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

static void DrawComboBoxField(PdfGraphics graphics)
{
    // Create a combo box field
    PdfGraphicsAcroFormComboBoxField comboBox =
        new PdfGraphicsAcroFormComboBoxField("combo Box", new RectangleF(20, 20, 100, 20));

    // Add values to the combo box.
    comboBox.AddValue("Red");
    comboBox.AddValue("Yellow");
    comboBox.AddValue("Green");
    comboBox.AddValue("Blue");

    // Specify combo box selected value, text alignment, and appearance.
    comboBox.SelectValue("Red");
    comboBox.TextAlignment = PdfAcroFormStringAlignment.Far;
    comboBox.Appearance.BackgroundColor = Color.Beige;
    comboBox.Appearance.FontSize = 14;

    // Add the field to the document.
    graphics.AddFormField(comboBox);
}
vb
Imports DevExpress.Pdf
Imports System.Drawing
'...

Shared Sub Main(ByVal args() As String)
    Using processor As New PdfDocumentProcessor()

        ' Create an empty document.
        processor.CreateEmptyDocument("..\..\Result.pdf")

        ' Create graphics and draw a combo box field.
        Using graphics As PdfGraphics = processor.CreateGraphicsPageSystem()
            DrawComboBoxField(graphics)

            ' Render a page with graphics.
            processor.RenderNewPage(PdfPaperSize.Letter, graphics)
        End Using
    End Using
End Sub

Private Shared Sub DrawComboBoxField(ByVal graphics As PdfGraphics)

    ' Create a combo box field
    Dim comboBox As New PdfGraphicsAcroFormComboBoxField("combo Box", New RectangleF(20, 20, 100, 20))

    ' Add values to the combo box.
    comboBox.AddValue("Red")
    comboBox.AddValue("Yellow")
    comboBox.AddValue("Green")
    comboBox.AddValue("Blue")

    ' Specify combo box selected value, text alignment, and appearance.
    comboBox.SelectValue("Red")
    comboBox.TextAlignment = PdfAcroFormStringAlignment.Far
    comboBox.Appearance.BackgroundColor = Color.Beige
    comboBox.Appearance.FontSize = 14

    ' Add the field to the document.
    graphics.AddFormField(comboBox)
End Sub

Inheritance

Object PdfGraphicsAcroFormField PdfGraphicsAcroFormCommonField PdfGraphicsAcroFormChoiceField PdfGraphicsAcroFormComboBoxField

PdfGraphicsAcroFormListBoxField

See Also

PdfGraphicsAcroFormChoiceField Members

DevExpress.Pdf Namespace