Skip to main content
This page explains how to build PDF templates from scratch. To scaffold a template, run npx pdfn add invoice (see Quickstart).

Template structure

Every template is a React component that exports a Document containing one or more Page components:
pdfn-templates/my-template.tsx
Save this file in pdfn-templates/ and it will appear in the dev server preview (npx pdfn dev).

Document

The root wrapper for every PDF template. Sets metadata and loads custom fonts.

Document props

Fonts

Pass font names for Google Fonts, or font config objects for local files:
See Styling — Fonts for configuration options and edge runtime considerations.

Page

Defines a page with size, margins, headers, footers, and content.

Page props

Page sizes

Margin formats

Watermark formats


PageNumber

Displays the current page number. Use in headers or footers.
Accepts a className prop for styling.

TotalPages

Displays the total page count. Combine with PageNumber for “Page 1 of 5” style footers.
Accepts a className prop for styling.

PageBreak

Forces content after it to start on a new page.

NoBreak

Keeps its children together on the same page. If the content doesn’t fit, it moves to the next page as a unit.
Use this for content blocks that shouldn’t be split across pages, like invoice line items or signature blocks.

Thead

For tables that span multiple pages, use Thead to make headers repeat on each page.
Thead repeats headers on each page by default. Pass repeat={false} to disable.
Standard HTML <thead> works but won’t repeat headers across pages. Use Thead for multi-page tables.
To prevent a table row from splitting across pages, use CSS: <tr style={{ breakInside: "avoid" }}>.

Next steps

Generate & Render

Client setup, generate() and render() parameters

Styling

Tailwind CSS, custom CSS, and inline styles