WeasyPrint Wrapper for .Net on Windows to generate pdf from html. It uses WeasyPrint to generate pdf from html without any extra installation and setup on Windows.
Gtb.WeasyPrint
simplifies the using of WeasyPrint on Windows, it is a minor change from Balbarak.WeasyPrint
It was forked to use in a web project which is executed under an app pool with no user profile, so I don't want to save files to appsettings.
As nuget package, the tb version is not on nuget.org, so first add a local repository and copy the .nupkg to it.
PM> Install-Package Gtb.WeasyPrint
It is also possible to install as dll reference, or even as a project reference.
using Gtb.WeasyPrint
using System.IO;
using (WeasyPrintClient client = new WeasyPrintClient(@"E:\path\to\weasy"))
{
var html = "<!DOCTYPE html><html><body><h1>Hello World</h1></body></html>";
var binaryPdf = await client.GeneratePdfAsync(html);
File.WriteAllBytes("result.pdf",binaryPdf);
}
using (WeasyPrintClient client = new WeasyPrintClient(@"E:\path\to\weasy"))
{
var input = @"path\to\input.html";
var output = @"path\to\output.pdf";
await client.GeneratePdfAsync(input,output);
}
using (WeasyPrintClient client = new WeasyPrintClient(@"E:\path\to\weasy"))
{
var input = @"path\to\input.html";
var output = @"path\to\output.pdf";
client.OnDataError += OnDataError;
client.OnDataOutput += OnDataOutput;
await client.GeneratePdfAsync(input,output);
}
private void OnDataOutput(OutputEventArgs e)
{
Console.WriteLine(args.Data);
}
private void OnDataError(OutputEventArgs e)
{
Console.WriteLine(e.Data);
}
- Balbarak/WeasyPrint-netcore - BSD-3-Clause license
- WeasyPrint - BSD 3-Clause License
- Python 3.6 Embedded - PSF License
- Gtk3 for Windows: Windows package, Documentation - LGPL 2