Skip to main content
Go from zero to a working PDF endpoint in your Next.js project. Everything runs locally — no API key needed until you deploy.
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

This creates 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:
This runs at 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

Visit http://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 same client.generate() call works with pdfn Cloud.
.env.local
Get your key at console.pdfn.dev.

Next steps

Dev Workflow

Live preview with hot reload

Components

Document, Page, and layout components

Styling

Tailwind CSS, custom CSS, and inline styles

Next.js

API routes, download buttons, and edge runtime