Skip to content

Latest commit

 

History

History
74 lines (53 loc) · 1.76 KB

README.md

File metadata and controls

74 lines (53 loc) · 1.76 KB

Nuget

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

Nuget

PM> Install-Package Balbarak.WeasyPrint

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 = await client.GeneratePdfAsync(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";

    await client.GeneratePdfAsync(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;

    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