Skip to content

candelaere/WeasyPrint-netcore

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

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.

Getting started

Installation

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.

Usage

From html text

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);
}

From html file

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);
}

Watch output and errors

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);
}

Third Parties

About

WeasyPrint Wrapper for .Net on Windows

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 94.1%
  • HTML 5.9%