Converting HTML to PDF
24 Jul 2020 / 10 minutes to read
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
-
Click more downloads option from the required product version. Refer to the following screenshot.
-
The HTML converter is available under the Add-On section. Refer to the following screenshot.
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);
Converting HTML to PDF using Blink rendering engine
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)
//Initialize 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");
FileStream fileStream = new FileStream("Sample.pdf", FileMode.CreateNew, FileAccess.ReadWrite);
//Save and close the PDF document
document.Save(fileStream);
document.Close(true);
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.
//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
Steps to apply the patch for HTML converter.
Download and extract the patch provided in the incident. Before applying the patch assemblies, the older assemblies should be removed from the GAC.
NOTE
You can uninstall or remove the specific version assemblies in GAC using the Syncfusion Assembly Manager Utility. Refer to the following Assembly Manager Documentation link for more information.
https://help.syncfusion.com/common/essential-studio/utilities#assembly-manager
Steps to replace the patch assemblies, if a customer using the HTML converter installer
This patch should replace the files HTML Converter patch assemblies under the following folder.
$system drive:\ Files\Syncfusion\Essential Studio$Version # \precompiledassemblies$Version#\4.6
Eg: $system drive:\Program Files\Syncfusion\Essential Studio\XX.X.X.XX\precompiledassemblies\XX.X.X.XX\4.6
The provided patch assembly should be used in your application.
Steps to replace the patch assemblies, if a customer using NuGet packages
- Uninstall the HTML to PDF converter NuGet package from the application.
- Download and extract the provided patch NuGet package.
- Now, you can install the required package in the .NET Framework or .Net Core application by using the NuGet package manager.
- Refer to this documentation link for installing NuGet packages.
Steps to update patch for QtBinaries or BinkBinaries folders
- Download and extract the Patch file for QtBinaries or BlinkBinaries folder.
- Copy the files from the Patch folder and replace or copy the files into the existing QtBinaries or BlinkBinaries folder.
- The patch applied QtBinaries or BlinkBinaries should be used in the applications to resolve the issue or the latest features.
WebKit
Eg: $system drive:\Program Files\Syncfusion\HTMLConverter\version\QtBinaries\
Blink
Eg: $system drive:\Program Files\Syncfusion\HTMLConverter\version\BlinkBinaries\
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 | ![]() |
![]() |
![]() |
Convert HTML string to PDF | ![]() |
![]() |
![]() |
Images | ![]() |
![]() |
![]() |
Hyperlinks | ![]() |
![]() |
![]() |
CSS | ![]() |
![]() |
![]() |
JavaScript | ![]() |
![]() |
![]() |
ActiveX plugin | ![]() |
![]() |
![]() |
HTML 5 | ![]() |
![]() |
![]() |
Page breaks | ![]() |
![]() |
![]() |
Vector Graphics (Selectable/searchable text) | ![]() |
![]() |
HTML 5 pages are rendered as bitmap. |
Handling image and text split across pages | ![]() |
![]() |
![]() |
Pdf A1-B | ![]() |
![]() |
![]() |
Tagged PDF | ![]() |
![]() |
![]() |
Page settings | ![]() |
![]() |
![]() |
Header and Footer | ![]() |
![]() |
![]() |
Windows Authentication | ![]() |
![]() |
![]() |
Form Authentication | ![]() |
![]() |
![]() |
HTML to Image | ![]() |
![]() |
![]() |
HTML to SVG | ![]() |
![]() |
![]() |
HTML to MHTML | ![]() |
![]() |
![]() |
SVG to PDF | ![]() |
![]() |
![]() |
HTML Form to PDF Form | ![]() |
![]() |
![]() |
HTTP GET and POST | ![]() |
![]() |
![]() |
Partial HTML to PDF | ![]() |
![]() |
![]() |
Bookmarks | ![]() |
![]() |
![]() |
Repeat HTML Table Header and Footer | ![]() |
![]() |
![]() |
Auto Create Table of Contents | ![]() |
![]() |
![]() |
Windows status | ![]() |
![]() |
![]() |
Print Media Type | ![]() |
![]() |
![]() |
Offline mode conversion | ![]() |
![]() |
![]() |
System proxy | ![]() |
![]() |
![]() |
Manual proxy | ![]() |
![]() |
![]() |
Azure App Service |
![]() |
![]() |
![]() |
Azure Cloud Service | ![]() |
![]() |
![]() |
Azure Function |
![]() |
![]() |
![]() |
Azure App Service with Linux docker | ![]() |
![]() |
![]() |