How to Create PDF Forms

by Chaknith

IronPDF offers a comprehensive set of form creation capabilities. It provides support for various types of form elements, including input fields, text areas, checkboxes, comboboxes, and radio buttons. With IronPDF, you can easily generate dynamic PDF forms that allow users to interact with the document by filling out form fields, making selections, and saving changes. This enables you to create interactive and user-friendly PDF forms for a wide range of applications and scenarios.

C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf
or
C# PDF DLL

Download DLL

Download DLL

Manually install into your project

Create Forms

IronPDF effortlessly create PDF documents with embedded form fields of various types. By adding dynamic form elements to an otherwise static PDF document, you can enhance its flexibility and interactivity.

Text Area and Input Forms

With IronPDF, you can easily create text area and input forms to capture user input within your PDF documents. Text area forms provide ample space for displaying and capturing larger amounts of text, while input forms allow users to enter specific values or responses.

:path=/static-assets/pdf/content-code-examples/how-to/create-forms-input-textarea.cs
using IronPdf;

// Input and Text Area forms HTML
string FormHtml = @"
<html>
    <body>
        <h2>Editable PDF Form</h2>
        <form>
            First name: <br> <input type='text' name='firstname' value=''> <br>
            Last name: <br> <input type='text' name='lastname' value=''> <br>
            Address: <br> <textarea name='address' rows='4' cols='50'></textarea>
        </form>
    </body>
</html>
";

// Instantiate Renderer
ChromePdfRenderer Renderer = new ChromePdfRenderer();
Renderer.RenderingOptions.CreatePdfFormsFromHtml = true;

Renderer.RenderHtmlAsPdf(FormHtml).SaveAs("textAreaAndInputForm.pdf");
Imports IronPdf

' Input and Text Area forms HTML
Private FormHtml As String = "
<html>
    <body>
        <h2>Editable PDF Form</h2>
        <form>
            First name: <br> <input type='text' name='firstname' value=''> <br>
            Last name: <br> <input type='text' name='lastname' value=''> <br>
            Address: <br> <textarea name='address' rows='4' cols='50'></textarea>
        </form>
    </body>
</html>
"

' Instantiate Renderer
Private Renderer As New ChromePdfRenderer()
Renderer.RenderingOptions.CreatePdfFormsFromHtml = True

Renderer.RenderHtmlAsPdf(FormHtml).SaveAs("textAreaAndInputForm.pdf")
VB   C#

Output PDF document

Checkbox and Combobox Forms

When working with checkbox forms in IronPDF, you can access the boolean property of a checkbox by explicitly casting the FormField to a CheckBoxField using the syntax (IronPdf.Forms.CheckBoxField)PdfDocument.Form.GetFieldByName("NameOfField"). This allows you to retrieve the selected state of the checkbox. Alternatively, you can check the Value property of the FormField object, where a selected checkbox will have a value of "On" and a not selected checkbox will have a value of "Off".

Combobox forms, providing users with a dropdown selection of options. Users can choose from the available options, providing valuable input within the PDF documents.

:path=/static-assets/pdf/content-code-examples/how-to/create-forms-checkbox-combobox.cs
using IronPdf;

// Load existing PDF document
PdfDocument pdf = PdfDocument.FromFile("Document.pdf");

// Add a bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0);

// Add a sub-bookmark within the previous
pdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1);

pdf.SaveAs("bookmarks.pdf");
Imports IronPdf

' Load existing PDF document
Private pdf As PdfDocument = PdfDocument.FromFile("Document.pdf")

' Add a bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0)

' Add a sub-bookmark within the previous
pdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1)

pdf.SaveAs("bookmarks.pdf")
VB   C#

Output PDF document

Radio buttons Forms

When working with radio button forms in IronPDF, each radio button is identified by its group using the name attribute in HTML. Radio buttons with the same name attribute are considered part of the same group, allowing only a single choice to be selected within that specific group. This ensures mutually exclusive selection within the group.

To access the selected choice from a radio button group, you can retrieve the value by accessing the Value property of the FormField object. Once a choice is selected, all the FormField objects within the same group will have the selected value.

:path=/static-assets/pdf/content-code-examples/how-to/create-forms-radiobutton.cs
using IronPdf;

// Radio buttons HTML
string FormHtml = @"
<html>
    <body>
        <h2>Editable PDF Form</h2>
        Choose your preferred travel type: <br>
        <input type='radio' name='traveltype' value='Bike'>
        Bike <br>
        <input type='radio' name='traveltype' value='Car'>
        Car <br>
        <input type='radio' name='traveltype' value='Airplane'>
        Airplane
    </body>
</html>
";

// Instantiate Renderer
ChromePdfRenderer Renderer = new ChromePdfRenderer();
Renderer.RenderingOptions.CreatePdfFormsFromHtml = true;

Renderer.RenderHtmlAsPdf(FormHtml).SaveAs("radioButtomForm.pdf");
Imports IronPdf

' Radio buttons HTML
Private FormHtml As String = "
<html>
    <body>
        <h2>Editable PDF Form</h2>
        Choose your preferred travel type: <br>
        <input type='radio' name='traveltype' value='Bike'>
        Bike <br>
        <input type='radio' name='traveltype' value='Car'>
        Car <br>
        <input type='radio' name='traveltype' value='Airplane'>
        Airplane
    </body>
</html>
"

' Instantiate Renderer
Private Renderer As New ChromePdfRenderer()
Renderer.RenderingOptions.CreatePdfFormsFromHtml = True

Renderer.RenderHtmlAsPdf(FormHtml).SaveAs("radioButtomForm.pdf")
VB   C#

Output PDF document

Chaknith Bin

Software Engineer

Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.