Create Fillable PDF Forms from HTML Forms

The converter can be configured to automatically create PDF forms that you can fill and submit from HTML forms using the PdfDocumentControlAutoPdfForm property of the HiQPdfClientAutoPdfForm type. A reference to an object of HiQPdfClient.PdfDocumentControl type is given by the Document property of the HiQPdfClient.HtmlToPdf class.

In order to enable the translation of HTML forms to PDF forms you have to set AutoPdfFormAutoCreatePdfForm property on true.

HTML Document Containing the HTML Form to Convert to a PDF Form

XML
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Auto Create PDF Forms from HTML Forms</title>
</head>
<body style="font-family: 'Times New Roman'; font-size: 14px">
    <form name="subscrForm" action="http://www.hiqpdf.com/formsubmitaction/" method="post">
        Name:<br />
        <input style="width: 200px" type="text" name="subscrName">
        <br />
        <br />
        Email :<br />
        <input style="width: 200px" type="text" name="subscrEmail"><br />
        <br />
        Website:<br />
        <input style="width: 200px" type="text" name="subscrWebsite"><br />
        <br />
        Password:<br />
        <input style="width: 200px" type="password" name="subscrPassword"><br />
        <br />
        Gender:&nbsp;
        <input type="radio" name="subscrGender" value="male" checked="checked">Male
        <input type="radio" name="subscrGender" value="female">Female<br />
        <br />
        Domains of interest:&nbsp;
        <select name="subscrDomains">
            <option value="science" selected="selected">Science</option>
            <option value="culture">Culture</option>
            <option value="music">Music</option>
        </select><br />
        <br />
        Newsletter:&nbsp;<input type="checkbox" name="receiveNewsletterEmail" value="email" checked="checked">By email
                    <input type="checkbox" name="receiveNewsletterPost" value="post">By post
        <br />
        <br />
        Short description:<br />
        <textarea name="subscrDescription" style="width: 300px; height: 100px"></textarea>
        <br />
        <br />
        <input type="submit" name="submitButton" value="Submit Form">
    </form>
</body>
</html>

Auto Create PDF Forms Demo

In this demo you learn how to automatically create a PDF form from a HTML form. You can fill and submit the generated PDF form.

Demo Source Code

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;

using HiQPdfClient;

namespace HiQPdf_Demo.Controllers
{
    public class AutoCreatePdfFormsController : Controller
    {
        // GET: AutoCreatePdfForms
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult ConvertToPdf(IFormCollection collection)
        {
            string serverIP = collection["textBoxServerIP"];
            uint serverPort = uint.Parse(collection["textBoxServerPort"]);
            string serverPassword = collection["textBoxServerPassword"];

            // create the HTML to PDF converter
            HtmlToPdf htmlToPdfConverter = new HtmlToPdf(serverIP, serverPort);

            // use server password if necessary
            if (serverPassword.Length > 0)
                htmlToPdfConverter.ServerPassword = serverPassword;

            // set a demo serial number
            htmlToPdfConverter.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            htmlToPdfConverter.BrowserWidth = 800;

            // automatically create a PDF form from HTML form
            htmlToPdfConverter.Document.AutoPdfForm.AutoCreatePdfForm = collection["checkBoxCreateForm"].Count > 0;

            // convert the HTML code to PDF
            byte[] pdfBuffer = htmlToPdfConverter.ConvertHtmlToMemory(collection["textBoxHtmlCode"], null);

            FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
            fileResult.FileDownloadName = "AutoPdfForms.pdf";

            return fileResult;
        }
    }
}

See Also