/WeasyPrint-netcore

WeasyPrint Wrapper for .Net on Windows

Primary LanguageC#

Introduction

WeasyPrint Wrapper for .Net on Windows to generate pdf from html. It uses WeasyPrint to generate pdf from html without any extra installtion and setup on Windows.

Balbarak.WeasyPrint simplifies the using of WeasyPrint on Windows

Getting started

Installation

From nuget packages

PM> Install-Package Balbarak.WeasyPrint -Version 0.7.1

Usage

From html text

using Balbarak.WeasyPrint
using System.IO;

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

    var binaryPdf = client.GeneratePdf(html);

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

From html file

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

    client.GeneratePdf(input,output;
}

Watch output and errors

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

    client.OnDataError += OnDataError;
    client.OnDataOutput += OnDataOutput;

    client.GeneratePdf(input,output;
}

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

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

Third Parties