Skip to main content
Import pdfn from @pdfn/react and create a client. It auto-detects your environment — local dev server, pdfn Cloud, or a custom endpoint.

Client setup

pdfn() reads the PDFN_API_KEY environment variable automatically. If set, it connects to pdfn Cloud. If not, it falls back to localhost:3456 for local development.

Client options


generate()

Generates a PDF and returns a buffer. Requires a running pdfn server (local dev server or pdfn Cloud).

Generate parameters

Metadata fields

These fields override the matching props on <Document>. If you set title on both <Document> and metadata, the metadata value wins.

Generate response

Examples

React component with options:
With debug overlays (development):
With idempotency key (deduplication):

render()

Renders a React component to a self-contained HTML string. Runs locally — no server required. Use this when you want to preview HTML or convert to PDF with your own Puppeteer/Playwright setup (see Self-Hosting).

Render parameters

Render response


Debug options

Both generate() and render() accept a debug option for development overlays:

Next steps

Troubleshooting

Error codes, common issues, and fixes

Self-Hosting

Run PDF generation on your own infrastructure