WeasyPrint.Wrapper
1.0.2
dotnet add package WeasyPrint.Wrapper --version 1.0.2
NuGet\Install-Package WeasyPrint.Wrapper -Version 1.0.2
<PackageReference Include="WeasyPrint.Wrapper" Version="1.0.2" />
<PackageVersion Include="WeasyPrint.Wrapper" Version="1.0.2" />
<PackageReference Include="WeasyPrint.Wrapper" />
paket add WeasyPrint.Wrapper --version 1.0.2
#r "nuget: WeasyPrint.Wrapper, 1.0.2"
#:package WeasyPrint.Wrapper@1.0.2
#addin nuget:?package=WeasyPrint.Wrapper&version=1.0.2
#tool nuget:?package=WeasyPrint.Wrapper&version=1.0.2
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:
From nuget packages
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
- WeasyPrint - BSD 3-Clause License
Product | Versions 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. |
-
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.