SelectPdf.Compat.WkHtmlToPdfDotNet 1.0.0

Prefix Reserved
dotnet add package SelectPdf.Compat.WkHtmlToPdfDotNet --version 1.0.0
                    
NuGet\Install-Package SelectPdf.Compat.WkHtmlToPdfDotNet -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SelectPdf.Compat.WkHtmlToPdfDotNet" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SelectPdf.Compat.WkHtmlToPdfDotNet" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SelectPdf.Compat.WkHtmlToPdfDotNet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SelectPdf.Compat.WkHtmlToPdfDotNet --version 1.0.0
                    
#r "nuget: SelectPdf.Compat.WkHtmlToPdfDotNet, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SelectPdf.Compat.WkHtmlToPdfDotNet@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SelectPdf.Compat.WkHtmlToPdfDotNet&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SelectPdf.Compat.WkHtmlToPdfDotNet&version=1.0.0
                    
Install as a Cake Tool

SelectPdf.Compat.WkHtmlToPdfDotNet

A free replacement for Haukcode.WkHtmlToPdfDotNet that keeps its API (IConverter, SynchronizedConverter, HtmlToPdfDocument, GlobalSettings, ObjectSettings, CoverSettings). Chromium does the rendering, through the free SelectPdf Community Edition, instead of wkhtmltopdf.

  • Keeps the Haukcode.WkHtmlToPdfDotNet API. The namespace and types are Haukcode.WkHtmlToPdfDotNet's, so existing code builds against this package.
  • No native wkhtmltopdf files and no apt-get install of wkhtmltopdf's Linux dependencies.
  • Runs on Windows x64/x86, Linux x64/ARM64, macOS on Apple Silicon, and Docker.
  • Renders modern HTML and CSS (flexbox, grid, web fonts, current JavaScript) through Chromium instead of the archived Qt WebKit.
  • Keeps the size of your content. CSS sizes are scaled the way wkhtmltopdf's smart shrinking scaled them, and content wider than the page is shrunk to fit.
  • Free for commercial use, up to 5 pages per document. See Limits.

This package is not affiliated with Haukcode.WkHtmlToPdfDotNet.

 

Migrate

dotnet remove package Haukcode.WkHtmlToPdfDotNet
dotnet add package SelectPdf.Compat.WkHtmlToPdfDotNet

Then add the SelectPdf engine package for the platform the application runs on: SelectPdf.Universal.Native.<rid>, where <rid> is win-x64, win-x86, linux-x64, linux-arm64 or osx-arm64. Reference one engine package per build, because they all install into the same folder. A project developed on Windows and deployed to a Linux container can pick the package by platform:

<PropertyGroup>
  <SelectPdfRid>$(RuntimeIdentifier)</SelectPdfRid>
  <SelectPdfRid Condition="'$(SelectPdfRid)' == '' And
      $([MSBuild]::IsOSPlatform('Windows'))">win-x64</SelectPdfRid>
  <SelectPdfRid Condition="'$(SelectPdfRid)' == ''">linux-x64</SelectPdfRid>
</PropertyGroup>
<ItemGroup>
  <PackageReference Include="SelectPdf.Universal.Native.$(SelectPdfRid)"
                    Version="26.5.0" />
</ItemGroup>

Remove the apt-get lines your Dockerfile needed for wkhtmltopdf (libgdiplus, fontconfig and the other libraries in its sample Dockerfile). Your code stays as it is:

using WkHtmlToPdfDotNet;
using WkHtmlToPdfDotNet.Contracts;

services.AddSingleton(typeof(IConverter),
    new SynchronizedConverter(new PdfTools()));

byte[] pdf = converter.Convert(new HtmlToPdfDocument
{
    GlobalSettings =
    {
        PaperSize = PaperKind.A4,
        Orientation = Orientation.Portrait,
        Margins = new MarginSettings { Top = 10 }
    },
    Objects =
    {
        new ObjectSettings
        {
            HtmlContent = html,
            FooterSettings = { Center = "Page [page] of [toPage]" }
        }
    }
});

 

Docker

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet publish -c Release -o /app

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "YourApp.dll"]

The engine package bundles the Chromium libraries, so the image needs no apt-get lines. On Linux, glibc 2.30 or later is required, which the official .NET images have. Linux images often have no fonts installed; the engine has built-in fonts for Latin scripts, and SelectPdf.Universal.Fonts adds every other script.

 

Limits

The Community Edition renders up to 5 pages per document. A longer document makes Convert throw an InvalidOperationException that says how many pages the document had, so a cut PDF never reaches your users unnoticed. To accept the first 5 pages instead, with a Warning event:

SelectPdfCompat.FailOnPageLimit = false;

Several objects in one document are joined into one HTML document with page breaks, so page numbering runs continuously across them. They must all use HtmlContent: a document with several objects where any of them is a URL (Page) needs PDF merging, which the free edition doesn't do, so it fails with a clear error.

For longer documents or URL merging, use SelectPdf.Compat.WkHtmlToPdfDotNet.Licensed, the same code on the licensed SelectPdf.Universal library.

 

How settings map

Haukcode.WkHtmlToPdfDotNet SelectPdf
PaperSize (any PaperKind or PechkinPaperSize) and Orientation Exact page size in points
Margins (mm, cm or in) Margins in points. Defaults to 10 mm on each side, as in wkhtmltopdf
HeaderSettings / FooterSettings: Left/Center/Right, FontName, FontSize, Line, Spacing Text sections placed inside the margin, as wkhtmltopdf placed them
[page], [topage], [frompage], [date], [isodate], [time], [title], [doctitle], [webpage] {page_number}, {total_pages}, or the value itself (case-insensitive, so [toPage] works)
HtmlUrl HTML header/footer section
ObjectSettings.Page (URL or local file) / HtmlContent ConvertUrl / ConvertHtmlString
Several Objects (HTML) One PDF, page breaks between objects
CoverSettings The cover goes first, with no header or footer
TableOfContentsSettings Skipped with a Warning (no generated TOC page); use Outline = true for bookmarks
ObjectSettings.Encoding Honoured by GetContent()
WebSettings.EnableIntelligentShrinking, LoadSettings.ZoomFactor The scale of the content, as wkhtmltopdf applied it
ColorMode.Grayscale Grayscale color space
DocumentTitle, Outline/OutlineDepth, ImageQuality, PageOffset, ViewportSize, Out Title, h1..hN bookmarks, JPEG level, first page number, browser viewport, file output (returns an empty array, as before)
WebSettings: PrintMediaType, EnableJavascript, Background, UserStyleSheet CSS media type, JavaScript, backgrounds, custom CSS
LoadSettings: Username/Password, JSDelay, Proxy, CustomHeaders, Cookies, BlockLocalFileAccess, Post HTTP auth, conversion delay (rounded up to whole seconds), proxy, headers, cookies, local file access, POST fields
Events: PhaseChanged, ProgressChanged, Finished, Error, Warning Raised at the same points

Settings with no equivalent, such as Copies, DPI and MinimumFontSize, are ignored. Each one raises the Warning event so you can see it.

 

What behaves differently

  • Engine. Chromium lays pages out like a current browser. Layouts that worked around WebKit's missing flexbox and grid support now render as written, and text metrics differ slightly. Use CSS break-before, break-after and break-inside: avoid to control page breaks.
  • HTML header/footer URLs. wkhtmltopdf passed ?page=&topage= to the HtmlUrl page. That isn't done here, so use text headers for page numbers.
  • Wide content without smart shrinking. With EnableIntelligentShrinking = false, content wider than the page is shrunk to fit instead of being cut at the right edge.
  • Several objects. The first content object's header, footer and web settings apply to the whole document.
  • Table of contents. No TOC page is generated; the PDF gets bookmarks when Outline is true.
  • Concurrency. SynchronizedConverter no longer queues every conversion on one thread. SelectPdf converts in parallel, so a singleton converter serves concurrent requests.
  • Failures. A failed conversion returns an empty array and raises Error, as before. Set SelectPdfCompat.ThrowOnError = true to throw instead.

 

Other SelectPdf options

SelectPdfCompat.Configure receives the SelectPdf.Universal.HtmlToPdf converter after your settings are applied, so you can set any other SelectPdf option:

SelectPdfCompat.Configure = (converter, obj) =>
    converter.Options.ConversionDelay = 2;

 

License

This package is MIT licensed. Its public API is based on DinkToPdf's (MIT, © 2017 Rok Dvojmoc; see THIRD-PARTY-DinkToPdf-LICENSE.txt), in WkHtmlToPdf-DotNet's namespace. No WkHtmlToPdf-DotNet (LGPL) source is included. Rendering uses the free SelectPdf Community Edition, © Outside Software SRL.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 0 10/15/2026