berthertogen / weasyprint.wrapped

A .netstandaard wrapper for the weasyprint PDF printer. This package is standalone and does not required you to install any software on your server. It runs on windows and linux.
BSD 3-Clause "New" or "Revised" License
25 stars 7 forks source link
dotnet html pdf weasyprint

build-test-code-scan

Introduction

Wrapper around the weasyprint library which allows you to print html to a pdf file. This package does not require any external software or packages to be installed in order to use weasyprint.

Getting started

Installation

NuGet Badge

dotnet add package Weasyprint.Wrapped

Usage

You might want to provide the printer class using your DI Container.

  1. Initialize
    This will unzip the needed asset, it is best done during startup procedure. The printer will check if the asset is already unzipped, so the process is only done once (or when the package is upgraded and the version changed).
    await new Printer().Initialize();
  2. Print
    await new Printer().Print("<html><body><h1>TEST</h1></body></html>");

    Warning

This is a large package, try to limit the projects where it will be installed.

Extra resources

References

Thanks to all these great repos and the guys maintaining them!!!

Weasyprint CLI

The weasyprint program takes at least two arguments:

weasyprint [options] <input> <output>

This option can be passed multiple times.

Contribute

Create test package and run example

Windows:

.\build-on-windows.ps1

Linux:

.\build-on-linux.ps1

Create package:

cd .\src\Weasyprint.Wrapped\
dotnet pack -p:PackageVersion=0.0.25 --output nupkgs

Update the example project package version (Weasyprint.Wrapped.Example.csproj) and run the example to test it

Error in tests

The following error might be thrown when running the tests on windows:

(process:13448): GLib-GIO-WARNING **: 17:21:45.816: Unexpectedly, UWP app `Microsoft.OutlookForWindows_1.2023.1114.100_x64__8wekyb3d8bbwe' (AUMId `Microsoft.OutlookForWindows_8wekyb3d8bbwe!Microsoft.OutlookforWindows') supports 1 extensions but has no verbs

Check here for the answer: https://stackoverflow.com/questions/67607643/what-does-this-warning-mean-it-happens-every-time-i-restart-the-node-process#answer-67715630

Building assets

Windows (build-on-windows.ps1 does approximately this)

Linux (build-on-linux.ps1 does approximately this)

Help