PDF Forms

C# + VB.Net: PDF Forms PDF Forms
           
// Step 1.  Creating a PDF with editable forms from HTML using form and input tags

var 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='' >
        </form>
    </body>
</html>";

IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
Renderer.PrintOptions.CreatePdfFormsFromHtml = true;
Renderer.RenderHtmlAsPdf(FormHtml).SaveAs("BasicForm.pdf");

// Step 2. Reading and Writing PDF form values.
var FormDocument = PdfDocument.FromFile("BasicForm.pdf");

//Set and Read the value of the "firstname" field
var FirstNameField =  FormDocument.Form.GetFieldByName("firstname");
FirstNameField.Value = "Minnie";
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value);

//Set and Read the value of the "lastname" field
IronPdf.Forms.FormField LastNameField = FormDocument.Form.GetFieldByName("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);

FormDocument.SaveAs("FilledForm.pdf");
' Step 1.  Creating a PDF with editable forms from HTML using form and input tags

Dim 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='' >
        </form>
    </body>
</html>"

Dim Renderer As New IronPdf.HtmlToPdf()
Renderer.PrintOptions.CreatePdfFormsFromHtml = True
Renderer.RenderHtmlAsPdf(FormHtml).SaveAs("BasicForm.pdf")

' Step 2. Reading and Writing PDF form values.
Dim FormDocument = PdfDocument.FromFile("BasicForm.pdf")

'Set and Read the value of the "firstname" field
Dim FirstNameField = FormDocument.Form.GetFieldByName("firstname")
FirstNameField.Value = "Minnie"
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value)

'Set and Read the value of the "lastname" field
Dim LastNameField As IronPdf.Forms.FormField = FormDocument.Form.GetFieldByName("lastname")
LastNameField.Value = "Mouse"
Console.WriteLine("LastNameField value: {0}", LastNameField.Value)

FormDocument.SaveAs("FilledForm.pdf")

PDFs with editable forms can be created from HTML simply by adding <<lform> <<linput> and <<ltextarea> tags. The PdfDocument.Form.GetFieldByName can be used to read and write the value of any form field. The name of the field will be the same as the 'name' attribute given to that field in your HTML. The PdfDocument.Form object can be used to: - Populate the default value of form fields (must be focused in Adobe Reader to display this value) - Read data from user filled PDF forms in any language.