How to convert HTML form to PDF form in C#?
The Syncfusion HTML to PDF converter is a .NET library for converting webpages, SVG, MHTML, and HTML to PDF using C#. It is reliable and accurate. The result preserves all graphics, images, texts, fonts, and the layout of the original HTML document or webpage.
Using this library, you can convert a HTML form to PDF form in C#. This application uses the following HTML form for HTML to PDF conversion.
Steps to convert the HTML form to PDF form programmatically in C#:
- Create a new C# console application project.
- Install the Syncfusion.HtmlToPdfConverter.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.
- Include the following namespaces in Program.cs file.
C#
using Syncfusion.HtmlConverter; using Syncfusion.Pdf; using System.IO;
- Include the following code snippet in Program.cs file, to convert a HTML form to PDF form.
C#
//Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Initialize Blink converter settings BlinkConverterSettings converterSettings = new BlinkConverterSettings(); //Enable the form to convert HTML form to PDF fillable form converterSettings.EnableForm = true; //Assign Blink settings to HTML converter settings htmlConverter.ConverterSettings = converterSettings; //Convert HTML to PDF document PdfDocument document = htmlConverter.Convert("HTMLForm.htm"); //Create file stream to save the PDF document FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); //Save and close the PDF document document.Save(fileStream); document.Close(true);
A complete work sample for converting a HTML form to PDF form can be downloaded from HTML-to-PDF-Conversion.zip.
By executing the program, you will get the PDF document as follows.
Take a moment to peruse the documentation, where you can find converting HTML pages to PDF document along with respective customization options and features.
Refer here to explore the rich set of Syncfusion Essential PDF features.
An online sample link to convert HTML to PDF document.
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.