Click or drag to resize
Pdf Library for .NET

Chromium Rendering Engine (CEF)

Introduced in v26.2 of SelectPdf. The Chromium rendering engine is based on the Chromium Embedded Framework (CEF). It is delivered as a separate Chromium.Windows NuGet package that complements the main Select.HtmlToPdf package. Pick it when the input HTML relies on modern HTML5/CSS3 or modern JavaScript (ES2020+) that the WebKit engines do not render correctly, or when the application needs to keep up with a current Chromium release.

The Chromium engine is available for every .NET target supported by Select.HtmlToPdf - .NET Framework 2.0, 4.0, 4.6.1, 4.7.2, and .NET Core 2.0 or later through .NET Standard 2.0 (including .NET 5 - .NET 10). It also runs on Microsoft Azure Web Apps (Basic plan or above) without additional configuration - see Deployment to Microsoft Azure.

NuGet Packages

Pick the Chromium.Windows package that matches the main Select.HtmlToPdf package already referenced in the project. The Chromium.Windows package installs the Chromium runtime alongside the base library - the main package is still required and is declared as a direct dependency of the Chromium.Windows package.

Select.HtmlToPdf.Chromium.Windows

Companion package for Select.HtmlToPdf (.NET Framework 2.0 and .NET 4.0 - 4.5, AnyCPU). Ships the x86 Chromium runtime.

https://www.nuget.org/packages/Select.HtmlToPdf.Chromium.Windows/

Select.HtmlToPdf.NetCore.Chromium.Windows

Companion package for Select.HtmlToPdf.NetCore (.NET Framework 4.6.1 and 4.7.2, .NET Core 2.0+ through .NET Standard 2.0, modern .NET 5 - .NET 10, AnyCPU). Ships the x86 Chromium runtime.

https://www.nuget.org/packages/Select.HtmlToPdf.NetCore.Chromium.Windows/

The .Windows suffix indicates that the Chromium runtime bundled with the package is the Windows build. The same Chromium engine is planned for other operating systems in future releases.

Note  Note

The Chromium.Windows packages are optional. Only install them when the application actually needs the Chromium engine. The main Select.HtmlToPdf packages still provide the WebKit, WebKit Restricted, and (on supported targets) Blink engines without them.

Selecting the Chromium Engine

Once the Chromium.Windows package is installed, select the engine by setting RenderingEngine to RenderingEngine.Chromium:

C#
VB
HtmlToPdf converter = new HtmlToPdf();

// select the Chromium rendering engine
converter.Options.RenderingEngine = RenderingEngine.Chromium;

// standard conversion options can still be used
converter.Options.PdfPageSize = PdfPageSize.A4;
converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait;
converter.Options.MarginTop = 20;
converter.Options.MarginBottom = 20;

PdfDocument doc = converter.ConvertUrl("https://selectpdf.com");

try
{
    doc.Save("ChromiumSample.pdf");
}
finally
{
    doc.Close();
}
Converting Authenticated Pages (Login Options)

The Chromium engine (like the Blink engine) can convert pages behind an HTML login form by populating LoginOptions on the converter options before conversion. LoginOptions takes the login page URL, the CSS selectors of the username, password and submit button fields, the credentials to type in, and optional delays before typing and after submitting.

C#
VB
HtmlToPdf converter = new HtmlToPdf();
converter.Options.RenderingEngine = RenderingEngine.Chromium;

converter.Options.LoginOptions = new LoginOptions
{
    LoginPage = "https://example.com/login",
    UsernameFieldSelector = "#username",
    PasswordFieldSelector = "#password",
    SubmitButtonSelector = "#submit",
    Username = "user@example.com",
    Password = "secret",
    DelayBefore = 100,
    DelayAfter = 500
};

PdfDocument doc = converter.ConvertUrl("https://example.com/protected");

try
{
    doc.Save("ProtectedPage.pdf");
}
finally
{
    doc.Close();
}
Feature Notes

The Chromium engine supports all Select.HtmlToPdf HTML-to-PDF features available with the default WebKit engine - including automatic bookmark generation and POST data.

See Also