Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

PdfAcroFormChoiceField.AddWidget(Int32, PdfRectangle) Method

Adds a widget annotation related to the choice form field (combo box or list box). Allows you to specify a page to which the widget should be added.

Namespace: DevExpress.Pdf

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

NuGet Package: DevExpress.Pdf.Core

#Declaration

public void AddWidget(
    int pageNumber,
    PdfRectangle rectangle
)

#Parameters

Name Type Description
pageNumber Int32

The number of a page to which to add the widget annotation (starting with 1).

rectangle PdfRectangle

The page rectangle where the widget annotation should be added.

#Remarks

A widget annotation contains form field display properties. One field can be related to multiple widget annotations. When you create a form field, the widget annotation is created automatically. Call the AddWidget method and pass the page number as the method parameter to create an additional widget on a separate page.

The code sample below creates a list box with one widget annotation on the first page, and another widget on the second page:

widgets

using DevExpress.Pdf;
using System.Globalization;

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

  // Create a list box field
  PdfAcroFormListBoxField listBox =
     new PdfAcroFormListBoxField("Language", 1, new PdfRectangle(230, 595, 330, 615));

  // Specify list box color and font size
  listBox.Appearance.BackgroundColor = new PdfRGBColor(0.8, 0.5, 0.3);
  listBox.Appearance.FontSize = 12;

  // Add values to the list box
  var allCultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
  foreach (var item in allCultures)
  {
      if (item!= null)
      {
          listBox.AddValue(item.DisplayName);
      }
  }

  listBox.MultiSelect = false;

  // Add a widget annotation on the second page
  listBox.AddWidget(2, new PdfRectangle(230, 595, 330, 615));

  // Add a form field
  processor.AddFormFields(textBox, radioGroup, listBox);

  // Save the result
  processor.SaveDocument("..\\..\\Result.pdf");
}
See Also