Adding a listbox control into PDF form document
The example demonstrates how to create a listbox using ByteScout PDF SDK.
Program.vb:
VB
'******************************************************************* ' ByteScout PDF SDK ' ' Copyright © 2016 Bytescout, https://bytescout.com ' ALL RIGHTS RESERVED ' '******************************************************************* Imports Bytescout.PDF ''' <summary> ''' This example demonstrates how to create a listbox. ''' </summary> Class Program Shared Sub Main() ' Create new document Dim pdfDocument = New Document() pdfDocument.RegistrationName = "demo" pdfDocument.RegistrationKey = "demo" ' Add page Dim page = New Page(PaperFormat.A4) pdfDocument.Pages.Add(page) ' Add list box, add items and make it multi-selectable Dim listBox1 = New ListBox(20, 20, 120, 80, "listBox1") listBox1.Items.Add("Value 1") listBox1.Items.Add("Value 2") listBox1.Items.Add("Value 3") listBox1.Items.Add("Value 4") listBox1.Items.Add("Value 5") listBox1.MultiSelect = True ' Decorate listbox listBox1.Font = New Font(StandardFonts.Helvetica, 10) listBox1.FontColor = New ColorRGB(0, 0, 128) listBox1.BorderColor = New ColorRGB(0, 0, 128) listBox1.BackgroundColor = New ColorRGB(240, 240, 255) listBox1.BorderWidth = 2 page.Annotations.Add(listBox1) ' Save document to file pdfDocument.Save("result.pdf") ' Cleanup pdfDocument.Dispose() ' Open document in default PDF viewer app Process.Start("result.pdf") End Sub End Class
Program.cs:
C#
//******************************************************************* // ByteScout PDF SDK // // Copyright © 2016 ByteScout - https://bytescout.com // ALL RIGHTS RESERVED // //******************************************************************* using System.Diagnostics; using Bytescout.PDF; namespace ListBoxes { /// <summary> /// This example demonstrates how to create a listbox. /// </summary> class Program { static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Add page Page page = new Page(PaperFormat.A4); pdfDocument.Pages.Add(page); // Add list box, add items and make it multi-selectable ListBox listBox = new ListBox(20, 20, 120, 80, "listBox1"); listBox.Items.Add("Value 1"); listBox.Items.Add("Value 2"); listBox.Items.Add("Value 3"); listBox.Items.Add("Value 4"); listBox.Items.Add("Value 5"); listBox.MultiSelect = true; // Decorate listbox listBox.Font = new Font(StandardFonts.Helvetica, 10); listBox.BorderColor = new ColorRGB(0, 0, 128); listBox.BackgroundColor = new ColorRGB(240, 240, 255); listBox.BorderWidth = 2; page.Annotations.Add(listBox); // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open document in default PDF viewer app Process.Start("result.pdf"); } } }