RndUsr0.DinkToPdf 1.0.9-20190207.1

This is a prerelease version of RndUsr0.DinkToPdf.
This package has a SemVer 2.0.0 package version: 1.0.9-20190207.1+netstandard-2.0-netcore-2.1-wkhtmltopdf-0.12.5.
dotnet add package RndUsr0.DinkToPdf --version 1.0.9-20190207.1
NuGet\Install-Package RndUsr0.DinkToPdf -Version 1.0.9-20190207.1
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="RndUsr0.DinkToPdf" Version="1.0.9-20190207.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RndUsr0.DinkToPdf --version 1.0.9-20190207.1
#r "nuget: RndUsr0.DinkToPdf, 1.0.9-20190207.1"
#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 RndUsr0.DinkToPdf as a Cake Addin
#addin nuget:?package=RndUsr0.DinkToPdf&version=1.0.9-20190207.1&prerelease

// Install RndUsr0.DinkToPdf as a Cake Tool
#tool nuget:?package=RndUsr0.DinkToPdf&version=1.0.9-20190207.1&prerelease

DinkToPdf

.NET Core P/Invoke wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.

Forked from the original project by Rok Dvojmoč, with updates to:

  • Upgrade to .NET Standard 2.0, .NET Core 2.1, wkhtmltopdf v0.12.5.
  • Fix the sporadic 'A callback was made on a garbage collected delegate' bug.

Install

Library can be installed through Nuget. Run command bellow from the package manager console:

PM> Install-Package RndUsr0.DinkToPdf

Copy native library to root folder of your project. From there .NET Core loads native library when native method is called with P/Invoke. You can find latest version of native library here. Select appropriate library for your OS and platform (64 or 32 bit).

IMPORTANT

Library was NOT tested with IIS. Library was tested in console applications and with Kestrel web server both for Web Application and Web API .

Basic converter

Use this converter in single threaded applications.

Create converter:

var converter = new BasicConverter(new PdfTools());

Synchronized converter

Use this converter in multi threaded applications and web servers. Conversion tasks are saved to blocking collection and executed on a single thread.

var converter = new SynchronizedConverter(new PdfTools());

Define document to convert

var doc = new HtmlToPdfDocument()
{
    GlobalSettings = {
        ColorMode = ColorMode.Color,
        Orientation = Orientation.Landscape,
        PaperSize = PaperKind.A4Plus,
    },
    Objects = {
        new ObjectSettings() {
            PagesCount = true,
            HtmlContent = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In consectetur mauris eget ultrices  iaculis. Ut                               odio viverra, molestie lectus nec, venenatis turpis.",
            WebSettings = { DefaultEncoding = "utf-8" },
            HeaderSettings = { FontSize = 9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 }
        }
    }
};

Convert

If Out property is empty string (defined in GlobalSettings) result is saved in byte array.

byte[] pdf = converter.Convert(doc);

If Out property is defined in document then file is saved to disk:

var doc = new HtmlToPdfDocument()
{
    GlobalSettings = {
        ColorMode = ColorMode.Color,
        Orientation = Orientation.Portrait,
        PaperSize = PaperKind.A4,
        Margins = new MarginSettings() { Top = 10 },
        Out = @"C:\DinkToPdf\src\DinkToPdf.TestThreadSafe\test.pdf",
    },
    Objects = {
        new ObjectSettings()
        {
            Page = "http://google.com/",
        },
    }
};
converter.Convert(doc);

Dependency injection

Converter must be registered as singleton.

public void ConfigureServices(IServiceCollection services)
{
    // Add converter to DI
    services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
}
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 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. 
.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 (2)

Showing the top 2 NuGet packages that depend on RndUsr0.DinkToPdf:

Package Downloads
Dex.PdfGenerator

Package Description

vamdemofeed

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.9-20190207.1 244,484 2/7/2019