DevBox.WkHtmlToPdf 1.0.8

dotnet add package DevBox.WkHtmlToPdf --version 1.0.8
                    
NuGet\Install-Package DevBox.WkHtmlToPdf -Version 1.0.8
                    
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="DevBox.WkHtmlToPdf" Version="1.0.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DevBox.WkHtmlToPdf" Version="1.0.8" />
                    
Directory.Packages.props
<PackageReference Include="DevBox.WkHtmlToPdf" />
                    
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 DevBox.WkHtmlToPdf --version 1.0.8
                    
#r "nuget: DevBox.WkHtmlToPdf, 1.0.8"
                    
#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 DevBox.WkHtmlToPdf@1.0.8
                    
#: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=DevBox.WkHtmlToPdf&version=1.0.8
                    
Install as a Cake Addin
#tool nuget:?package=DevBox.WkHtmlToPdf&version=1.0.8
                    
Install as a Cake Tool

DevBox.WkHtmlToPdf

NuGet Version

A simple wrapper for wkhtmltopdf, enabling conversion of HTML or Razor Views directly into PDF files within ASP.NET Core applications.

This is a refactor from Wkhtmltopdf.NetCore since is deprecated.
It's also important to read this recommendations.


Installation

  1. Add DevBox.WkHtmlToPdf package to your project:
dotnet add package DevBox.WkHtmlToPdf
  1. Download the desirable version of wkhtmltopdf and add to your project:
.
├── MyProject
│   ├── WkHtmlToPdf
│   │   ├── Windows
│   │   │   └── wkhtmltopdf.exe
│   │   └── Linux
│   │       └── wkhtmltopdf
│   └── MyProject.csproj
└── MyProject.sln
OS/Distribution Supported on Architectures
Windows 64-bit
Debian 11 bullseye 64-bit

The package could copy the binaries automatically and verify the OS, but it would be large. This way the executable becomes configurable.

  • Edit your .csproj:
<ItemGroup>
    <Content Include="WkHtmlToPdf\**\*.*">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
</ItemGroup>

If you have wkhtmltopdf installed in your server, you can skip item 2 configuring through SetExecutableFilePath using an absolute path.

  1. Configure your IServiceCollection:
services.AddHttpContextAccessor();
services.AddWkHtmlToPdf(options =>
{
    options.SetExecutableFilePath("custom-absolute-path/wkhtmltopdf.exe");

    // Customize the default options
    options.Title = "My PDF";
    options.PageSize = PageSize.A4;
    options.Orientation = PdfOrientation.Landscape;
    // ...
});
  • Default executable file path:
    • Windows: WkHtmlToPdf/Windows/wkhtmltopdf.exe
    • Linux: WkHtmlToPdf/Linux/wkhtmltopdf
    • MAC: WkHtmlToPdf/Mac/wkhtmltopdf
  1. If you work with Linux or Docker, you need to install libgdiplus and libc6-dev.
apt-get update
apt-get -y install libgdiplus libc6-dev
FROM mcr.microsoft.com/dotnet/aspnet:7.0
# ...
RUN apt-get update -qq && apt-get -y install libgdiplus libc6-dev
  • If you have problems with differents fonts in Windows vs Docker, you can try:
RUN apt-get update -qq && apt-get -y install libgdiplus libc6-dev fontconfig fonts-liberation
RUN fc-cache -f -v

Usage

Inject IPdfConverterService in any class you need.

  1. Converting a HTML:
var buffer = await _pdfConverterService.FromHtmlAsync("<html>...</html>", options =>
{
    // Overrides the default options
    options.Title = "My Report";
});
  1. Converting a Razor View:
var buffer = await _pdfConverterService.FromViewAsync("PathToView/ViewName", model, options =>
{
    // Overrides the default options
    options.HeaderFooter.HeaderHtml = "PathToView/HeaderViewName";
});
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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 was computed.  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. 
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.8 587 4/9/2025