This sample shows how to use list boxes in your PDF document.

You can add a list box to your PDF document using PdfPage.AddListBox(..) method. The AddListBox method returns an instance of PdfListBox class.

Use PdfListBox.AddItems(..) method to add items to the list box. Use PdfListBox.SelectItems(..) method to select items in the list box.

C#
using System.Diagnostics;

using BitMiracle.Docotic.Pdf;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class Listboxes
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "Listboxes.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfPage page = pdf.Pages[0];

                PdfListBox listBox = page.AddListBox(10, 50, 120, 80);
                listBox.AddItem("First item");
                listBox.AddItem("Second item");
                listBox.AddItem("Third item");
                listBox.MultiSelection = true;

                PdfListItem[] items =
                {
                    new PdfListItem("One", "1"),
                    new PdfListItem("Two", "2"),
                    new PdfListItem("Three", "3"),
                };
                PdfListBox listBox2 = page.AddListBox(10, 140, 120, 80);
                listBox2.AddItems(items);
                listBox2.SelectItems(new PdfListItem[] { items[0], items[2] });

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
    }
}
VB
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class Listboxes
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.

            Dim pathToFile As String = "Listboxes.pdf"

            Using pdf As New PdfDocument()
                Dim page As PdfPage = pdf.Pages(0)

                Dim listBox As PdfListBox = page.AddListBox(10, 50, 120, 80)
                listBox.AddItem("First item")
                listBox.AddItem("Second item")
                listBox.AddItem("Third item")
                listBox.MultiSelection = True

                Dim items As PdfListItem() = {New PdfListItem("One", "1"), New PdfListItem("Two", "2"), New PdfListItem("Three", "3")}
                Dim listBox2 As PdfListBox = page.AddListBox(10, 140, 120, 80)
                listBox2.AddItems(items)
                listBox2.SelectItems(New PdfListItem() {items(0), items(2)})

                pdf.Save(pathToFile)
            End Using

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace