AdaskoTheBeAsT.WkHtmlToX 7.1.0

dotnet add package AdaskoTheBeAsT.WkHtmlToX --version 7.1.0
NuGet\Install-Package AdaskoTheBeAsT.WkHtmlToX -Version 7.1.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="AdaskoTheBeAsT.WkHtmlToX" Version="7.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AdaskoTheBeAsT.WkHtmlToX --version 7.1.0
#r "nuget: AdaskoTheBeAsT.WkHtmlToX, 7.1.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.
// Install AdaskoTheBeAsT.WkHtmlToX as a Cake Addin
#addin nuget:?package=AdaskoTheBeAsT.WkHtmlToX&version=7.1.0

// Install AdaskoTheBeAsT.WkHtmlToX as a Cake Tool
#tool nuget:?package=AdaskoTheBeAsT.WkHtmlToX&version=7.1.0

WkHtmlToX

C# wrapper for wkhtmltopdf.org Html to Pdf and Image library.

Badges

CodeFactor Total alerts Build Status Azure DevOps tests Azure DevOps coverage Quality Gate Status Sonar Tests Sonar Test Count Sonar Test Execution Time Sonar Coverage Nuget

Usage

In web api (in combination with SimpleInjector) registration should be as follows:

   // for simplicity only version for win here
    var configuration = new WkHtmlToXConfiguration((int)Environment.OSVersion.Platform, null);
    _container.RegisterInstance(configuration);
    _container.RegisterSingleton<IWkHtmlToXEngine, WkHtmlToXEngine>();
    _container.RegisterSingleton<IPdfConverter, PdfConverter>();
    _container.RegisterInitializer<IWkHtmlToXEngine>(e => e.Initialize());

In command line application:

    // for simplicity only version for win here
    var configuration = new WkHtmlToXConfiguration((int)Environment.OSVersion.Platform, null);
    using (var engine = new WkHtmlToXEngine(configuration))
    {
        engine.Initialize();

        var converter = new PdfConverter(engine);
    }

Method for conversion to pdf takes 3 parameters. First is settings object in which there is possibility to pass html content to be converted. In second parameter you need to pass func which based on length will create stream. In third you need to pass CancellationToken.

Second parameter is tricky but such construction allows to use for example Microsoft.IO.RecyclableMemoryStream to reuse block of memories. Then whole conversion can look like this

    // doc settings object created earlier
    Stream? stream = null;
    var converted = await _pdfConverter.ConvertAsync(
        doc,
        length =>
        {
            stream = _recyclableMemoryStreamManager.GetStream(
                Guid.NewGuid(),
                "wkhtmltox",
                length);
            return stream;
        },
        _httpContextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None);
    stream!.Position = 0;
    if (converted)
    {
        var result = new FileStreamResult(stream, "application/pdf")
        {
            FileDownloadName = "sample.pdf",
        };

        return result;
    }

WkHtmlToX native lib comes with support for following operation system flavours:

  • WinX64,
  • WinX86,
  • OsxX64,
  • AmazonLinux2,
  • Centos6,
  • Centos7,
  • Centos8,
  • Debian9X64,
  • Debian9X86,
  • Debian10X64,
  • Debian10X86,
  • OpenSuseLeap15,
  • Ubuntu1404X64,
  • Ubuntu1404X86,
  • Ubuntu1604X64,
  • Ubuntu1604X86,
  • Ubuntu1804X64,
  • Ubuntu1804X86,
  • Ubuntu2004X64,

For linux you can set it using second parameter in config.

    var configuration = new WkHtmlToXConfiguration((int)PlatformID.Unix, WkHtmlToXRuntimeIdentifier.Ubuntu2004X64);

Influencers

Library is based on wrapper (DinkToPdf)[https://github.com/rdvojmoc/DinkToPdf]. Interoperability was totally reworked and now it is under tests to see if leaking memory can be avoided.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 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 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. 
.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.
  • .NETStandard 2.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

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
7.1.0 179 12/27/2023
7.0.0 128 12/5/2023
6.0.0 452 11/13/2022
5.0.0 436 2/23/2021
4.0.3 416 1/16/2021
4.0.1 419 12/3/2020
4.0.0 451 7/8/2020
3.0.3 493 4/22/2020
3.0.2 479 4/19/2020
3.0.1 456 4/19/2020
3.0.0 502 3/29/2020
2.0.0 508 3/28/2020
1.1.0 590 12/15/2019
1.0.0 511 12/8/2019