FrontierJS

Print kit

UI · Print@frontierjs/print-kit

A document to a PDF, an element to a PNG, in one headless Chrome.

$ npm i @frontierjs/print-kit

Rendering

printer.pdf(html) · printer.png(html, selector)

One Chrome, opened on the first job and reused after. It drives the browser with the same tool the component tests use, so an app that prints adds no second browser driver.

import { createPrinter, printDocument } from '@frontierjs/print-kit'

const printer = createPrinter()
const pdf = await printer.pdf(printDocument({ title, body, css }))
await printer.close()

Replaces

PuppeteerPlaywrightwkhtmltopdf

In an app

app.configure(printer()) gives you app.printer

With no Chrome on the machine, the app refuses to start and says why. You find out at boot, not on the first invoice.

Replaces

Nothing — there is no common equivalent to swap out.

Safety

The page runs offline with scripts off

A printed document is built from data somebody else entered. A URL in it cannot make your server fetch anything, and markup in a name runs nothing.

Replaces

sanitizing every field by hand

Pages

print.css handles page breaks and margins

Every printed document carries it after the app’s own styles, so page groups, break rules and margin boxes are already set up.

Replaces

Paged.jsprint styles written per document