https://github.com/ericbf/node-weasyprint
https://github.com/ericbf/node-weasyprint
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/ericbf/node-weasyprint
- Owner: ericbf
- License: mit
- Created: 2023-01-19T21:46:25.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-21T03:13:00.000Z (over 2 years ago)
- Last Synced: 2025-03-26T08:40:08.067Z (about 1 year ago)
- Language: TypeScript
- Size: 325 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Node WeasyPrint
_A NodeJS wrapper for [WeasyPrint](https://doc.courtbouillon.org/weasyprint/stable/index.html)_
This module is basically a complete complete rewrite of [Trim/weasyprint-wrapper](https://github.com/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](https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installation), 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](https://doc.courtbouillon.org/weasyprint/stable/api_reference.html#command-line-api) applies.
## Usage
Example:
```ts
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("
Test
Hello world
", {
buffer: true
})
// Save in a file
try {
await weasyprint("
Test
Hello world
", { output: "test.pdf" })
} catch (err) {
console.error(err)
}
```
> WeasyPrint [does not provide support](https://doc.courtbouillon.org/weasyprint/stable/common_use_cases.html#adjust-document-dimensions) 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