Skip to main content
This page covers Next.js patterns for both routers. For initial setup, see the Quickstart.

API route

Accept a request body and return a PDF:
app/api/invoice/route.tsx

Download button

Trigger a PDF download from a client component:
app/page.tsx

Client components

Templates that use "use client" components (like Recharts or other chart libraries) need the withPdfn() build plugin to pre-bundle them for rendering. If you followed the Quickstart, this is already set up:
next.config.ts
The plugin detects templates with "use client" directives and bundles them at build time. No additional configuration needed.

Edge runtime

Edge runtimes (Vercel Edge, Cloudflare Workers) don’t have filesystem access. The withPdfn() build plugin handles this by pre-compiling Tailwind CSS at build time. What to keep in mind on edge:
  • Tailwind works — pre-compiled by withPdfn(), no filesystem needed at runtime
  • Local images and fonts won’t load — use remote URLs or base64 data URIs instead
  • client.generate() works — connects to pdfn Cloud for PDF generation, no local dependencies needed

Project structure

Environment variables

.env.local
Get your key at console.pdfn.dev. Without PDFN_API_KEY, the client uses localhost:3456 automatically. Run npx pdfn dev alongside your Next.js dev server for local development.

Next steps

Components

Document, Page, and layout components

Troubleshooting

Error codes, common issues, and fixes