Browser printing guide

Practical guide to printing DocStudio documents from the browser: the print target, page size and margins, fonts, saving as PDF, and common problems.

Browser printing is the simplest output path: no server, no Playwright and no Chromium install on your side. See the quick version for the call. This guide covers what makes the result good.

Render the print target

const result = renderDocument(template, data, { target: 'print', title: 'Statement' });

The print target writes your template's page size and margins as @page rules. A template with config.page.size: "A4" and margins: 18 prints on A4 with 18 mm margins, whatever the default of the user's printer dialog.

Page furniture

Put repeating content in page.header and page.footer. Page numbers use {n} and {total}, and both are real in print output.

Fonts

The browser prints with the fonts available to the page. To use a font that the user may not have, register it with createFontRegistry and pass fonts to renderDocument. Faces are embedded in the document as data URIs.

Save as PDF

Every major browser can save the print result as a PDF from the print dialog. That is a user action, so you cannot name the file or run it in the background. If you need a file generated for the user, use server-side PDF.

Troubleshooting

Symptom Likely cause
Backgrounds are missing The user's print dialog has background graphics off. The print target asks the browser to print colors exactly, but a dialog setting can still override it in some browsers
Margins differ from the template The user chose custom margins in the dialog
Text uses a different font The font is not installed and was not registered with fonts
Page count differs between browsers Each browser's print engine paginates on its own. Use the server for identical files
The dialog does not open The call did not come from a user gesture, or pop-ups and printing are blocked

From the designer

The designer's Print action calls the same helper with the current template and sample data.

Last updated 2026-12-03