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.
<!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:
<input type="radio" name="subscrGender" value="male" checked="checked">Male
<input type="radio" name="subscrGender" value="female">Female<br />
<br />
Domains of interest:
<select name="subscrDomains">
<option value="science" selected="selected">Science</option>
<option value="culture">Culture</option>
<option value="music">Music</option>
</select><br />
<br />
Newsletter: <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>
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.
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;
}
}
}