0.1.1 • Published 6 months ago

node-weasyprint v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Node WeasyPrint

A NodeJS wrapper for WeasyPrint

This module is basically a complete complete rewrite of Trim/weasyprint-wrapper, and the fork chain there. This version has Typescript support, correct options parsing, and other improvements.

Getting started

Since this is only a wrapper, you do still need the WeasyPrint binary. You’re better off following their installation instructions, but it may be as simple as installing it with pip3:

pip3 install weasyprint

With the binary installed, install this package from npm:

npm i node-weasyprint

Since this uses the CLI interface under the hook, the WeasyPrint command line API applies.

Usage

Example:

import weasyprint from "node-weasyprint"

// URL, specifying the format & default command to spawn weasyprint
const stream = await weasyprint("https://google.com/", {
	command: "~/programs/weasyprint"
})

// HTML
const buffer = await weasyprint("<h1>Test</h1><p>Hello world</p>", {
	buffer: true
})

// Save in a file
try {
	await weasyprint("<h1>Test</h1><p>Hello world</p>", { output: "test.pdf" })
} catch (err) {
	console.error(err)
}

WeasyPrint does not provide support for adjusting page size or document margins via flags. This is best accomplished with the CSS @page at-rule. Consider the following example:

@page {
	size: Letter; /* Change from the default size of A4 */
	margin: 3cm; /* Set margin on each page */
}

License

MIT

0.1.1

6 months ago

0.1.0

8 months ago

0.0.6

8 months ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago