Not using Next.js? pdfn works with any framework. Install
@pdfn/react and @pdfn/tailwind, then use the same client.generate() API.Prerequisites
- Node.js 22 or higher
- A Next.js project (App Router or Pages Router)
1. Install
2. Add the build plugin
next.config.ts
3. Add a template
pdfn-templates/invoice.tsx with sample data.
Want to build templates from scratch? See Components.
4. Start the dev server
In one terminal, start the pdfn preview server:http://localhost:3456 with live preview of your templates. See Dev Workflow for details.
In another terminal, start Next.js:
5. Create an API route
app/api/invoice/route.tsx
Using Pages Router? See the Pages Router example.
6. Test it
Visithttp://localhost:3000/api/invoice in your browser. You should see your PDF.
Going to production
Add your API key and deploy. No code changes needed — the sameclient.generate() call works with pdfn Cloud.
.env.local
| Environment | What happens |
|---|---|
| No API key | Uses local dev server (localhost:3456) |
pdfn_test_* key | Uses pdfn Cloud (adds watermark) |
pdfn_live_* key | Uses pdfn Cloud (production) |