Skip to footer content
USING IRONPDF

Generating Fillable PDF Forms from HTML in C#

Intake forms, applications, surveys, and onboarding paperwork all share a pattern: a recipient needs to fill in fields and return the document. A static PDF cannot do that, and printing, scanning, and re-keying wastes everyone's time. IronPDF generates fillable PDF forms in C#, either from HTML markup the team already has or by placing fields programmatically onto an existing document.

The Business Problem

A healthcare provider needs patient intake forms, an insurer needs applications, an HR team needs onboarding documents. Each should arrive as a PDF the recipient can complete on screen, ideally with known details already filled in. Building these by hand in a PDF editor does not scale, and maintaining a separate form layout duplicates the web version that often already exists.

Generating a Form from HTML

Enabling one rendering option turns standard HTML form elements into interactive PDF fields, so existing markup becomes a fillable document.

using IronPdf;

string formHtml = @"
<html><body>
  <h2>Patient Intake</h2>
  <form>
    First name: <input type='text' name='firstname' value=''><br>
    Address: <textarea name='address' rows='4' cols='50'></textarea><br>
    Completed: <input type='checkbox' name='completed'><br>
    Priority:
    <select name='priority'>
      <option value='high'>High</option>
      <option value='low'>Low</option>
    </select>
  </form>
</body></html>";

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
renderer.RenderHtmlAsPdf(formHtml).SaveAs("intake-form.pdf");
using IronPdf;

string formHtml = @"
<html><body>
  <h2>Patient Intake</h2>
  <form>
    First name: <input type='text' name='firstname' value=''><br>
    Address: <textarea name='address' rows='4' cols='50'></textarea><br>
    Completed: <input type='checkbox' name='completed'><br>
    Priority:
    <select name='priority'>
      <option value='high'>High</option>
      <option value='low'>Low</option>
    </select>
  </form>
</body></html>";

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
renderer.RenderHtmlAsPdf(formHtml).SaveAs("intake-form.pdf");
Imports IronPdf

Dim formHtml As String = "
<html><body>
  <h2>Patient Intake</h2>
  <form>
    First name: <input type='text' name='firstname' value=''><br>
    Address: <textarea name='address' rows='4' cols='50'></textarea><br>
    Completed: <input type='checkbox' name='completed'><br>
    Priority:
    <select name='priority'>
      <option value='high'>High</option>
      <option value='low'>Low</option>
    </select>
  </form>
</body></html>"

Dim renderer As New ChromePdfRenderer()
renderer.RenderingOptions.CreatePdfFormsFromHtml = True
renderer.RenderHtmlAsPdf(formHtml).SaveAs("intake-form.pdf")
$vbLabelText   $csharpLabel

Because each field has a name and a value, the same approach pre-fills a form from a database, so a renewal notice or application arrives with the recipient's details already populated and only the gaps left to complete.

Adding Fields to an Existing Document

When the base document did not come from HTML, such as a scanned form or a generated report needing an approval field, fields can be placed programmatically at exact coordinates.

using IronSoftware.Forms;

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h2>Approval</h2>");

var textForm = new TextFormField("approver", "", pageIndex: 0, x: 100, y: 700, width: 150, height: 15);
pdf.Form.Add(textForm);

pdf.SaveAs("approval-form.pdf");
using IronSoftware.Forms;

PdfDocument pdf = renderer.RenderHtmlAsPdf("<h2>Approval</h2>");

var textForm = new TextFormField("approver", "", pageIndex: 0, x: 100, y: 700, width: 150, height: 15);
pdf.Form.Add(textForm);

pdf.SaveAs("approval-form.pdf");
Imports IronSoftware.Forms

Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h2>Approval</h2>")

Dim textForm As New TextFormField("approver", "", pageIndex:=0, x:=100, y:=700, width:=150, height:=15)
pdf.Form.Add(textForm)

pdf.SaveAs("approval-form.pdf")
$vbLabelText   $csharpLabel

Points to Plan For

  • Enable the form flag: Without CreatePdfFormsFromHtml set to true, HTML form elements render as static visuals rather than fillable fields. This is the most common reason a form is not editable.
  • Programmatic fields are coordinate-based: Fields added through code use absolute x, y, width, height, and a page index, which is precise but makes layout your responsibility.
  • Checkbox values: A checkbox uses "yes" and "no" rather than a boolean for its checked state.
  • Creating is not securing: Generating a form does not lock or sign it. Apply passwords, permissions, or signatures separately when the document needs protection.

Result

With one option for HTML forms and coordinate-based fields for everything else, teams ship fillable, pre-fillable documents that recipients complete on screen, with no manual form building. Full field types and options are in the create PDF forms guide.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me