Articles in this section
Category / Section

How to convert HTML form to PDF form in C#?

4 mins read

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.

HTML Form in .NET PDF

Steps to convert the HTML form to PDF form programmatically in C#:

  1. Create a new C# console application project. Create a console application in Visual Studio in .NET PDF
  2. Install the Syncfusion.HtmlToPdfConverter.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.

Add NuGet package as reference in .NET PDF

  1. Include the following namespaces in Program.cs file.

C#

using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
using System.IO;

 

  1. 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.

Output document screenshot in .NET PDF

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.

Note:

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.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please  to leave a comment
Access denied
Access denied