VintaSoft Imaging .NET SDK 15.1: Документация для .NET разработчика
В этом разделе
PDF: Добавление поля с выпадающим списком в интерактивную форму PDF
В этом разделе
Вот C#/VB.NET код, который демонстрирует, как создать поле с выпадающим списком и добавить его в интерактивную форму PDF документа:
class PdfInteractiveFormComboBoxFieldExample
{
    /// <summary>
    /// Creates a PDF document with the combo box fields.
    /// </summary>
    /// <param name="filename">The filename.</param>
    public static void CreateDocumentWithComboBoxField(string filename)
    {
        // create PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument())
        {
            // create interactive form in PDF document
            document.InteractiveForm = 
                new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);

            // specify that the viewer application must construct appearance streams and
            // appearance properties for all widget annotations
            document.InteractiveForm.NeedAppearances = true;

            // create an empty page
            Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
                document, Vintasoft.Imaging.PaperSizeKind.A4);
            // add page to the document
            document.Pages.Add(page);

            float width = 70;
            float height = 20;
            // create a rectangle that defines check box position on PDF page
            System.Drawing.RectangleF rect = new System.Drawing.RectangleF(
                (page.Size.Width - width) / 2,
                ((page.Size.Height - height) / 3) * 2,
                width, height);

            // create a combo box field
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormComboBoxField comboBox = 
                new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormComboBoxField(
                    document, "ComboBox1", rect, new string[] { "Item1", "Item2", "Item3" });
            // set the selected item
            comboBox.SelectedItem = "Item2";
            // set the defaul selected item
            comboBox.DefaultSelectedItem = comboBox.SelectedItem;
            
            // set the border style
            comboBox.Annotation.BorderStyle = 
                new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document);
            comboBox.Annotation.BorderStyle.Style = 
                Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled;
            comboBox.Annotation.BorderStyle.Width = 1;
            
            // set the appearance characteristics
            comboBox.Annotation.AppearanceCharacteristics = 
                new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document);
            comboBox.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray;
            
            // sets the default appearance of text
            Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
                Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
            comboBox.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black);

            // add combo box field to the interactive form of document
            document.InteractiveForm.Fields.Add(comboBox);

            // add annotation, associated with combobox field, to the page
            page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
            page.Annotations.Add(comboBox.Annotation);

            // save the document
            document.Save(filename);
        }
    }
}
Class PdfInteractiveFormComboBoxFieldExample
    ''' <summary>
    ''' Creates a PDF document with the combo box fields.
    ''' </summary>
    ''' <param name="filename">The filename.</param>
    Public Shared Sub CreateDocumentWithComboBoxField(filename As String)
        ' create PDF document
        Using document As New Vintasoft.Imaging.Pdf.PdfDocument()
            ' create interactive form in PDF document
            document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)

            ' specify that the viewer application must construct appearance streams and
            ' appearance properties for all widget annotations
            document.InteractiveForm.NeedAppearances = True

            ' create an empty page
            Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A4)
            ' add page to the document
            document.Pages.Add(page)

            Dim width As Single = 70
            Dim height As Single = 20
            ' create a rectangle that defines check box position on PDF page
            Dim rect As New System.Drawing.RectangleF((page.Size.Width - width) / 2, ((page.Size.Height - height) / 3) * 2, width, height)

            ' create a combo box field
            Dim comboBox As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormComboBoxField(document, "ComboBox1", rect, New String() {"Item1", "Item2", "Item3"})
            ' set the selected item
            comboBox.SelectedItem = "Item2"
            ' set the defaul selected item
            comboBox.DefaultSelectedItem = comboBox.SelectedItem

            ' set the border style
            comboBox.Annotation.BorderStyle = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document)
            comboBox.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled
            comboBox.Annotation.BorderStyle.Width = 1

            ' set the appearance characteristics
            comboBox.Annotation.AppearanceCharacteristics = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document)
            comboBox.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray

            ' sets the default appearance of text
            Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
            comboBox.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black)

            ' add combo box field to the interactive form of document
            document.InteractiveForm.Fields.Add(comboBox)

            ' add annotation, associated with combobox field, to the page
            page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
            page.Annotations.Add(comboBox.Annotation)

            ' save the document
            document.Save(filename)
        End Using
    End Sub
End Class