API route
Accept a request body and return a PDF:- App Router
- Pages Router
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
"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. ThewithPdfn() 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
PDFN_API_KEY, the client uses localhost:3456 automatically. Run npx pdfn dev alongside your Next.js dev server for local development.