Html to Pdf Converter for .NET - HTML Rendering Engines | |
SelectPdf offers 4 HTML rendering engines that can be selected via the RenderingEngine property:
WebKit (default) - the engine that has been available since the first version of SelectPdf. Covers every .NET Framework and .NET Core/.NET Standard target. Best choice when the input HTML relies on ES5 JavaScript and classic CSS.
WebKit Restricted - a simplified WebKit engine that can run in constrained environments like Microsoft Azure Web Apps. Same ES5 feature footprint as the default WebKit, with some features disabled.
Blink - the rendering engine from the Chrome browser. Available for SelectPdf .NET Core builds and for .NET Framework 4.6.1 and above. Supports modern HTML5/CSS3 and ES6 JavaScript.
Chromium (introduced in v26.2) - a rendering engine based on the Chromium Embedded Framework (CEF), shipped as a separate Chromium.Windows NuGet package. Tracks a current Chromium release and supports the latest HTML5/CSS3 and modern JavaScript (ES2020+). Available for every supported .NET target.
The following sample shows how to use the Select.Pdf HTML to PDF converter to convert a URL to PDF while selecting the rendering engine.
// instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter rendering engine converter.Options.RenderingEngine = RenderingEngine.WebKit; // or: RenderingEngine.WebKitRestricted // or: RenderingEngine.Blink // or: RenderingEngine.Chromium // create a new pdf document converting an url PdfDocument doc = converter.ConvertUrl(url); // save pdf document doc.Save(Response, false, "Sample.pdf"); // close pdf document doc.Close();
Use the following guidance when picking an engine:
Start with WebKit (the default). It is available on every supported target and handles most traditional web content.
For Microsoft Azure Web Apps (or a similar restricted environment), use either WebKit Restricted or Chromium. Both run on Azure Web Apps (Basic plan or above) without additional configuration; pick Chromium when modern HTML5/CSS3 or modern JavaScript rendering is needed, WebKit Restricted otherwise.
Switch to Blink or Chromium when the input HTML needs modern CSS3, HTML5 or modern JavaScript that the WebKit engines do not render correctly.
Prefer Chromium over Blink when the application targets legacy .NET Framework (2.0 - 4.5) and still needs a modern engine, when the application runs on Azure Web Apps, or when the application needs to keep up with a current Chromium version. The Chromium engine ships in a separate Chromium.Windows NuGet package - see Installation for details.
Partial web page rendering (converting only a CSS-selected region via VisibleWebElementId) is supported only by the WebKit rendering engines - it is not available with Blink or Chromium. Use the default WebKit engine when that feature is required.
All four engines are exposed through the same HtmlToPdf API. Switching engines is a one-line change on RenderingEngine.
This is the default rendering engine, available since the first version of SelectPdf. Unless otherwise specified, all features described in this documentation that relate to HTML to PDF conversion refer to this engine. WebKit is available for every .NET Framework and .NET Core version supported by SelectPdf.
Note: the WebKit rendering engine can only render ES5 JavaScript.
Introduced in v18.3 of SelectPdf. Also based on WebKit, with fewer features so it can run in restricted environments such as Microsoft Azure Web Apps. WebKit Restricted is available for every .NET Framework and .NET Core version supported by SelectPdf.
Note: the WebKit Restricted rendering engine can only render ES5 JavaScript.
Introduced in v19.1 of SelectPdf. Only available for SelectPdf builds that target .NET Core 2.0 or above and .NET Framework 4.6.1 or above. Blink is the rendering engine used by the Chrome browser and the Chromium project.
Blink can render the latest HTML/CSS and ES6 JavaScript. Most HTML-to-PDF features available with the default WebKit engine - including automatic bookmark generation, POST data, web elements location retrieval, and table of contents generation - are also supported when rendering with Blink. Partial web page rendering (converting only a CSS-selected region via VisibleWebElementId) is the one exception: for HTML to PDF it is supported only by the WebKit engines.
Introduced in v26.2 of SelectPdf. The Chromium rendering engine is based on the Chromium Embedded Framework (CEF) and is distributed as a separate Chromium.Windows NuGet package that complements the main SelectPdf package. It renders modern HTML5/CSS3 and modern JavaScript (ES2020+), and tracks a current Chromium release.
Unlike the Blink engine, the Chromium engine is available for every .NET target supported by SelectPdf, including .NET Framework 2.0 and 4.0. The Chromium engine also runs on Microsoft Azure Web Apps (Basic plan or above) without additional configuration.
Authenticated web pages can be converted with the Chromium engine by populating LoginOptions on HtmlToPdfOptions.
All SelectPdf HTML-to-PDF features - including automatic bookmark generation, POST data, partial web page rendering, web elements location retrieval, and table of contents generation - are fully supported with Chromium.
For installation and deployment details see Chromium Engine.