Converting HTML to PDF

Essential PDF supports converting HTML pages to PDF document. The converter offers full support for HTML tags, HTML5, CSS3, JavaScript, SVG and page breaks. The following are the three rendering engines:

  • WebKit rendering
  • Blink rendering
  • IE rendering

Steps to download the HTML converter installer

  • The latest version of Essential HTML converter can be downloaded from

    https://www.syncfusion.com/downloads/latest-version

  • Click more downloads option from the required product version. Refer to the following screenshot.
    Download page

  • The HTML converter is available under the Add-On section. Refer to the following screenshot.
    HTML converter

Getting Started

Essential PDF supports converting HTML contents to PDF. To add the HTML to PDF conversion functionality, add the following assemblies as reference to the project.

Assembly Name Description
Syncfusion.HtmlConverter.Base This is required for converting HTML to PDF.
Syncfusion.Pdf.Base Contains the core feature for creating, manipulating, and saving PDF documents.
Syncfusion.Compression.Base This is required for compressing the internal contents of a PDF document.

Include the following namespaces in your .cs or .vb file as follows.

using Syncfusion.Pdf;
using Syncfusion.HtmlConverter;
Imports Syncfusion.Pdf
Imports Syncfusion.HtmlConverter
using Syncfusion.Pdf;
using Syncfusion.HtmlConverter;

Converting HTML to PDF using WebKit rendering engine

To convert website URL or local HTML file to PDF using WebKit rendering engine, refer to the following code snippet. Click the following link for more details to convert the HTML to PDF using WebKit rendering engine.

Conversion using WebKit Rendering

//Initialize the HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);

WebKitConverterSettings settings = new WebKitConverterSettings();
            
//Set WebKit path
settings.WebKitPath = @"/QtBinaries/";
            
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;

//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://www.google.com");

//Save and close the PDF document 
document.Save("Output.pdf");

document.Close(true);
'Initialize the HTML to PDF converter 
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.WebKit)

Dim settings As New WebKitConverterSettings()

'Set WebKit path
settings.WebKitPath = "/QtBinaries/"

'Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings

'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com")

'Save and close the PDF document 
document.Save("Output.pdf")

document.Close(True)
//Initialize the HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();

WebKitConverterSettings settings = new WebKitConverterSettings();

//Set WebKit path
settings.WebKitPath = @"\QtBinariesDotNetCore\";

//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;

//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://www.google.com");

FileStream fileStream = new FileStream("Sample.pdf", FileMode.CreateNew, FileAccess.ReadWrite);
            
//Save and close the PDF document 
document.Save(fileStream);
document.Close(true);

To convert website URL or local HTML file to PDF using Blink rendering engine, refer to the following code snippet. Click the following link for more details to convert the HTML to PDF using Blink rendering engine.

Conversion using Blink Rendering

//Initialize the HTML to PDF converter with Blink rendering engine
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);

BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();

//Set the BlinkBinaries folder path
blinkConverterSettings.BlinkPath = @"/BlinkBinaries/";

//Assign Blink converter settings to HTML converter
htmlConverter.ConverterSettings = blinkConverterSettings;

//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://www.google.com");

//Save and close the PDF document 
document.Save("Output.pdf");

document.Close(true);
'Initialize the HTML to PDF converter with Blink rendering engine
Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter(HtmlRenderingEngine.Blink)

Dim blinkConverterSettings As BlinkConverterSettings = New BlinkConverterSettings()

'Set the BlinkBinaries folder path
blinkConverterSettings.BlinkPath = "/BlinkBinaries/"

'Assign Blink converter settings to HTML converter
htmlConverter.ConverterSettings = blinkConverterSettings

'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com")

'Save and close the PDF document 
document.Save("Output.pdf")

document.Close(True)
//Currently, Blink rendering engine does not support conversion in .NET Core platform

Converting HTML to PDF using IE rendering engine

To convert website URL or local HTML file to PDF using IE rendering engine, refer to the following code snippet. Click the following link for more details to convert the HTML to PDF using IE rendering engine.

Conversion using IE Rendering

//Initialize the HTML to PDF converter 
 HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.IE);

IEConverterSettings settings = new IEConverterSettings();
            
//Assign IE settings to HTML converter
htmlConverter.ConverterSettings = settings;

//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("https://www.google.com");

//Save and close the PDF document 
document.Save("Output.pdf");

document.Close(true);
'Initialize the HTML to PDF converter 
Dim htmlConverter As New HtmlToPdfConverter(HtmlRenderingEngine.IE)

Dim settings As New IEConverterSettings()

'Assign IE settings to HTML converter
htmlConverter.ConverterSettings = settings

'Convert URL to PDF
Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com")

'Save and close the PDF document 
document.Save("Output.pdf")

document.Close(True)
//Currently, IE rendering engine does not support conversion in .NET Core platform

Supported and Unsupported Features by Rendering Engines

The following table shows the WebKit, Blink and IE rendering engines supported features:

Feature WebKit Renderer Blink Renderer IE Renderer
Convert URLs to PDF Yes Yes Yes
Convert HTML string to PDF Yes Yes Yes
Images Yes Yes Yes
Hyperlinks Yes Yes Yes
CSS Yes Yes Yes
JavaScript Yes Yes Yes
ActiveX plugin Yes Yes Yes
HTML 5 Yes Yes Yes
Page breaks Yes Yes Yes
Vector Graphics (Selectable/searchable text) Yes Yes HTML 5 pages are rendered as bitmap.
Handling image and text split across pages Yes Yes Yes
Pdf A1-B No No Yes
Tagged PDF No No Yes
Page settings Yes Yes Yes
Header and Footer Yes Yes Yes
Windows Authentication Yes Yes Yes
Form Authentication Yes Yes No
HTML to Image Yes Yes Yes
HTML to SVG Yes No No
HTML to MHTML Yes No No
SVG to PDF Yes Yes No
HTML Form to PDF Form Yes No Yes
HTTP GET and POST Yes Yes No
Partial HTML to PDF Yes No No
Bookmarks Yes No No
Repeat HTML Table Header and Footer Yes Yes(Works only with print media) No
Auto Create Table of Contents Yes No No
Windows status Yes Yes No
Print Media Type Yes Yes No
Offline mode conversion Yes Yes No
System proxy Yes Yes Yes
Manual proxy Yes No No