Adding Form Fields to a PDF
Add form fields such as buttons, checkboxes, combo boxes, list boxes, radio buttons, and text fields to a PDF document. DynamicPDF Core Suite for .NET makes creating interactive forms a breeze, as the following C# examples illustrate.
Hot to Add Button to PDF
The following steps and C# sample code illustrates adding a Button to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding a Button to a PDF Document
- Create a
Documentobject. - Create a
Pageobject. - Create a
Buttonobject and set its properties. - Add the
Buttoninstance to thePageinstance. - Add the
Pageinstance to theDocumentinstance. - Add the
Drawmethod to output the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page(PageSize.Letter);
Button button = new Button("btn", 50, 50, 100, 50);
button.Action = new JavaScriptAction("app.alert('Hello');");
button.Label = "Click";
page.Elements.Add(button);
document.Pages.Add(page);
document.Draw("Output.pdf");

How to Add CheckBox to PDF
The following steps and C# sample code add a CheckBox to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding a Checkbox to a PDF Document
- Create a
Documentobject. - Create
Pageobject. - Create a
CheckBoxobject and set its properties. - Add the
CheckBoxinstance to thePageinstance - Add the
Pageinstance toDocumentinstance. - Add the
Drawmethod to output the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page(PageSize.Letter);
CheckBox checkBox = new CheckBox( "Check Box Name", 5, 7, 50, 50 );
checkBox.DefaultChecked = true;
checkBox.ToolTip = "Check it";
page.Elements.Add(checkBox);
document.Pages.Add(page);
document.Draw("Output.pdf");

How to Add ComboBox to PDF
The following steps and C# sample code illustrate adding a ComboBox to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding a ComboBox to a PDF Document
- Create a
Documentobject. - Create a
Pageobject. - Create a
ComboBoxobject and set its properties. - Add the
ComboBoxinstance to thePageinstance. - Add the
Pageinstance to theDocumentobject instance. - Add the
Drawmethod to output the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page(PageSize.Letter);
ComboBox comboBox = new ComboBox( "Combo Box Name", 50, 75, 150, 25);
comboBox.Items.Add("One", true);
comboBox.Items.Add("Two");
comboBox.Items.Add("Three");
comboBox.BackgroundColor = RgbColor.AliceBlue;
comboBox.BorderColor = RgbColor.DarkMagenta;
comboBox.Editable = true;
comboBox.ToolTip = "Select";
page.Elements.Add(comboBox);
document.Pages.Add(page);
document.Draw("Output.pdf");

How to Add ListBox to PDF
The following steps and C# sample code illustrate adding a ListBox to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding a ListBox to a PDF Document
- Create a
Documentobject. - Create a
Pageobject. - Create a
ListBoxobject and set its properties. - Add the
ListBoxobject to thePageobject. - Add the
Pageobject to theDocumentobject. - Add the
Drawmethod to output the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page(PageSize.Letter);
ListBox listBox = new ListBox( "List Box Name", 5, 2, 100, 150 );
listBox.Items.Add( "One",true );
listBox.Items.Add( "Two",true );
listBox.Items.Add( "Three" );
listBox.BackgroundColor = RgbColor.AliceBlue;
listBox.BorderColor = RgbColor.DarkMagenta;
listBox.BorderStyle = BorderStyle.Dashed;
listBox.Multiselect = true;
listBox.ToolTip = "Select";
page.Elements.Add(ListBox);
document.Pages.Add(page);
document.Draw("Output.pdf");

How to Add Radio Button to PDF
The following steps and C# sample code illustrate adding a Radio Button to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding a RadioButton to a PDF Document
- Create a
Documentobject. - Create a
Pageobject. - Create a
RadioButtonobject and set its properties. - Add the
RadioButtonobject instance to thePageinstance. - Add the
Pageobject to theDocument object. - Add the
Drawmethod to output the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page(PageSize.Letter);
RadioButton radio1 = new RadioButton( "Radio Button Name", 50, 25, 100, 75 );
radio1.DefaultChecked = true;
radio1.ExportValue = "abc";
radio1.ToolTip = "first";
RadioButton radio2 = new RadioButton( "Radio Button Name", 50, 140, 100, 75 );
radio2.ExportValue = "def";
radio2.ToolTip = "second";
RadioButton radio3 = new RadioButton( "Radio Button Name", 50, 250, 100, 75 );
radio3.ExportValue = "ghi";
radio3.ToolTip = "third";
page.Elements.Add(radio1);
page.Elements.Add(radio2);
page.Elements.Add(radio3);
document.Pages.Add(page);
document.Draw("Output.pdf");

How to Add Text Field to PDF
The following steps and C# sample code add a TextField to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding a TextField to PDF Document
- Create a
Documentobject. - Create a
Pageobject. - Create a
TextFieldobject and set its properties. - Add the
TextFieldobject to thePageobject. - Add the
Pageobject to theDocumentobject. - Add the
Drawmethod to output the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page(PageSize.Letter);
TextField textField = new TextField( "Text Field Name", 50, 75, 150, 100 );
textField.TextAlign = Align.Center;
textField.BackgroundColor = RgbColor.AliceBlue;
textField.BorderColor = RgbColor.DeepPink;
textField.Font = Font.TimesItalic;
textField.FontSize = 16.0f;
textField.TextColor = RgbColor.Brown;
textField.DefaultValue = "ceTe Software";
textField.MultiLine = true;
textField.ToolTip = "Text";
page.Elements.Add(textField);
document.Pages.Add(page);
document.Draw(@"Output.pdf");

GitHub Project
An example project is available on GitHub (examples.dynamicpdf-core-suite-dotnet-core). Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This specific example discussed on this page are all contained in following classes on GitHub
- C# - AddFormFieldsExample.cs
- VB.NET - AddFormFieldsExample.vb
Getting Started
Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing the product.
NuGet Package
The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.
DynamicPDF Core Suite Information
DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!
More Information on Form Fields
- Refer to the Interactive Forms Overview documentation topic, or
- Chapter 15, Creating Interactive Forms, in the book DynamicPDF Core Suite for .NET by Example available on GitHub.
Available on Other Platforms
DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- DynamicPDF Generator
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX
- DynamicPDF Merger
- Java - DynamicPDF Merger for Java
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX