Rzaw / WeasyPrint-netcore

WeasyPrint Wrapper for .Net on Windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

WeasyPrint Wrapper for .Net on Windows


Languages

Language:C# 94.1%Language:HTML 5.9%