WeasyPrint.Wrapper 1.0.2

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

Nuget

Introduction

WeasyPrint Wrapper for .Net on Windows / Linux / MacOS (Though not tested on MacOS (due to unavailability of Mac Machine), but it might work) to generate pdf from html. It uses WeasyPrint to generate pdf from html. This package assumes that WeasyPrint is installed and working on your machine. This package is a modified version of Balbarak.WeasyPrint.

WeasyPrint.Wrapper simplifies the using of WeasyPrint on Windows / Linux

Getting started

Installation

For WeasyPrint installation follow WeasyPrint documentation:

WeasyPrint Documentation

From nuget packages

Nuget

PM> Install-Package WeasyPrint.Wrapper

Usage

From html text

using WeasyPrint.Wrapper;
using System.IO;

public class ConsoleTraceWriter : ITraceWriter
{
    public void Info(string message)
    {
        Console.WriteLine(message);
    }

    public void Verbose(string message)
    {
        
    }
}

string workingDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
var trace = new ConsoleTraceWriter();

using (WeasyPrintClient client = new WeasyPrintClient(trace, workingDir))
{
    var html = "<!DOCTYPE html><html><body><h1>Hello World</h1></body></html>";

    var binaryPdf = await client.GeneratePdfAsync(html);

    File.WriteAllBytes("result.pdf",binaryPdf);
}

From html file

using (WeasyPrintClient client = new WeasyPrintClient(trace, workingDir))
{
    var input = @"path\to\input.html";
    var output = @"path\to\output.pdf";

    await client.GeneratePdfAsync(input, output);
}

Watch output and errors

using (WeasyPrintClient client = new WeasyPrintClient(trace, workingDir))
{
    var input = @"path\to\input.html";
    var output = @"path\to\output.pdf";

    client.OnDataError += OnDataError;
    
    await client.GeneratePdfAsync(input, output);
}

private void OnDataError(OutputEventArgs e)
{
    Console.WriteLine(e.Data);
}

Third Parties

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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
1.0.2 197 2/25/2025
1.0.1 111 2/25/2025
1.0.0 102 2/25/2025