PdfGraphicsAcroFormComboBoxField Class
A combo box field in PDF Graphics API.
Namespace: DevExpress.Pdf
Assembly: DevExpress.Pdf.v21.2.Drawing.dll
Declaration
Remarks
To access the PdfGraphicsAcroFormComboBoxField
class, reference the DevExpress.Pdf.Drawing.v21.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 Combo Box Form Field
Create a new PdfGraphicsAcroFormComboBoxField
object, and pass the field name and location as the constructor parameters.
You can also call the PdfGraphicsAcroFormField.CreateComboBox method to create a combo box field. The page location is calculated in the world coordinate system.
To add values to a combo box, call one of the AddValue overloaded methods.
Specify Form Field Parameters
The following parameters are available:
Parameter | API |
---|---|
Form field name | Name |
Tooltip text | ToolTip |
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 field as graphics content, pass a PdfGraphicsAcroFormComboBoxField
object as a parameter to the PdfGraphics.AddFormField method.
Draw a Form Field on a Page
To add an interactive field to a page, call one of the following methods:
- PdfGraphics.AddToPageForeground, PdfGraphics.AddToPageBackground – to add a field to an existing page;
- PdfDocumentProcessor.RenderNewPage – to add a field to a new page.
Example
This example shows how to use PDF Graphics API to create a combo box field and add it to a PDF page.
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.CreateGraphics())
{
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);
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the PdfGraphicsAcroFormComboBoxField class.
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.