Adding Form Fields to PDF
Different types of form fields can be easily added to a PDF using DynamicPDF Core Suite. Form fields such as Button, CheckBox, ComboBox, ListBox, RadioButton, and TextField can all be added to a PDF document.
How to Add Buttons to a PDF in C#
The following steps and sample code illustrates adding Buttons to a PDF document using DynamicPDF Core Suite.
Steps for Adding Buttons to a PDF Document
- Create a
Document
object. - Create a
Page
object instances. - Create a
Button
object and set its properties. - Add the
Button
object instance to the Page instance. - Add the Page instance to the Document instance.
- Save 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 a Checkbox to PDF in C#
The following steps and sample code add a Checkbox to a PDF document using DynamicPDF Core Suite.
Steps for Adding Checkbox to a PDF Document
- Create a
Document
object. - Create
Page
object instance. - Create a
CheckBox
object and set its properties. - Add the CheckBox instance to the Page instance
- Add the Page instance to Document instance.
- Save 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 a ComboBox to a PDF in C#
The following steps and sample code illustrate adding a ComboBox to a PDF document using DynamicPDF Core Suite.
Steps for Adding 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 the Page instance. - Add the
Page
instance to the Document object instance. - Save 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 in C#
The following steps and sample code illustrate adding a ListBox to a PDF document using DynamicPDF Core Suite.
Steps for Adding ListBox to PDF Document
- Create a
Document
object. - Create a
Page
object. - Create a
ListBox
object and set its properties. - Add the
ListBox
object to the Page object. - Add the Page object to the Document object.
- Save 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 in C#
The following steps and sample code illustrate adding a Radio Button to a PDF document using DynamicPDF Core Suite.
Steps for Adding Radio Button 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 the Page instance.
- Add the Page object to the Document object.
- Save 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 Fields to PDF in C#
The following steps and sample code add Text Fields to a PDF document using DynamicPDF Core Suite.
Steps for Adding Text Fields to PDF Document
- Create a
Document
object. - Create a
Page
object. - Create a
TextField
object and set its properties. - Add the TextField object to the Page object.
- Add the Page object to the Document object.
- Save 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
Clone or view the example project at GitHub. This example code is contained in the Examples/AddFormFieldsExample.cs file.
Getting Started
NuGet Package
The easiest way to install DynamicPDF Core Suite is by using the Visual Studio Package Manger to install the NuGet package. You can also download the NuGet package directly using the following link.
DynamicPDF Core Suite Information
More information on DynamicPDF Core Suite can be found at the following web page.
Available on Other Platforms
The DynamicPDF Core Suite is also available for Java and COM/ActiveX. Refer to the respective product pages for more details.
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX