Examples

Add Form Fields to PDF (.NET Core/Framework)

Different types of Form Fields can be added to PDF easily using DynamicPDF Generator product. Form fields like Button, CheckBox, ComboBox, ListBox, RadioButton and TextField can be added to a PDF document.

How to add Buttons to PDF in C#

Below are the steps and sample code to add Buttons to PDF document using the Generator product.

Steps for Adding Buttons to a PDF Document

  1. Create a Document object.
  2. Create as many Page object as needed.
  3. Create a Button object and set the properties.
  4. Add Button to the Page.
  5. Add Page to the Document.
  6. 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(@"C:\Output.pdf");        

How to add Checkbox to PDF in C#

Below are the steps and sample code to add Checkbox to PDF document using the Generator product.

Steps for Adding Checkbox to a PDF Document

  1. Create a Document object.
  2. Create as many Page object as needed.
  3. Create a CheckBox object and set the properties.
  4. Add CheckBox to the Page.
  5. Add Page to the Document.
  6. 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(@"C:\Output.pdf");        

How to add ComboBox to PDF in C#

Below are the steps and sample code to add ComboBox to PDF document using the Generator product.

Steps for Adding ComboBox to a PDF Document

  1. Create a Document object.
  2. Create as many Page object as needed.
  3. Create a ComboBox object and set the properties.
  4. Add ComboBox to the Page.
  5. Add Page to the Document.
  6. 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.Draw(@"C:\Output.pdf");        

How to add ListBox to PDF in C#

Below are the steps and sample code to add ListBox to PDF document using the Generator product.

Steps for Adding ListBox to a PDF Document

  1. Create a Document object.
  2. Create as many Page object as needed.
  3. Create a ListBox object and set the properties.
  4. Add ListBox to the Page.
  5. Add Page to the Document.
  6. 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.Draw(@"C:\Output.pdf");        

How to add Radio Button to PDF in C#

Below are the steps and sample code to add Radio Button to PDF document using the Generator product.

Steps for Adding Radio Button to a PDF Document

  1. Create a Document object.
  2. Create as many Page object as needed.
  3. Create a RadioButton object and set the properties.
  4. Add RadioButton to the Page.
  5. Add Page to the Document.
  6. 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(@"C:\Output.pdf");        

How to add Text Fields to PDF in C#

Below are the steps and sample code to add Text Fields to PDF document using the Generator product.

Steps for Adding Text Fields to a PDF Document

  1. Create a Document object.
  2. Create as many Page object as needed.
  3. Create a TextField object and set the properties.
  4. Add TextField to the Page.
  5. Add Page to the Document.
  6. 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(@"C:\Output.pdf");        

Getting Started

NuGet Package

DynamicPDF Generator is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET package. The Core Suite package includes Generator, Merger and ReportWriter.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

DynamicPDF CoreSuite Information

More information on DynamicPDF CoreSuite can be found here:

Java and COM/ActiveX Platforms

The DynamicPDF Generator is also available for Java and COM/ActiveX. Refer to the respective product pages for more details.

Why Choose DynamicPDF?

  • Transparent Pricing
  • Lots of Features
  • Easy to Use
  • Great Support
  • Efficient Performance
  • Product Maturity (Over 18 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

We’re Not The Only Ones That Think We’re Great!