Adding Form Fields to 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 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
Document
object. - Create a
Page
object. - Create a
Button
object and set its properties. - Add the
Button
instance to thePage
instance. - Add the
Page
instance to theDocument
instance. - Add the
Draw
method 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
Document
object. - Create
Page
object. - Create a
CheckBox
object and set its properties. - Add the
CheckBox
instance to thePage
instance - Add the
Page
instance toDocument
instance. - Add the
Draw
method 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
Document
object. - Create a
Page
object. - Create a
ComboBox
object and set its properties. - Add the
ComboBox
instance to thePage
instance. - Add the
Page
instance to theDocument
object instance. - Add the
Draw
method 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
Document
object. - Create a
Page
object. - Create a
ListBox
object and set its properties. - Add the
ListBox
object to thePage
object. - Add the
Page
object to theDocument
object. - Add the
Draw
method 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
Document
object. - Create a
Page
object. - Create a
RadioButton
object and set its properties. - Add the
RadioButton
object instance to thePage
instance. - Add the
Page
object to theDocumen
t object. - Add the
Draw
method 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
Document
object. - Create a
Page
object. - Create a
TextField
object and set its properties. - Add the
TextField
object to thePage
object. - Add the
Page
object to theDocument
object. - Add the
Draw
method 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