Skip to main content
Every generate() and render() call returns { data, error } instead of throwing. Check error before using data.

Basic pattern

Error object

PdfnError is a class that extends Error:
You can use instanceof to check for pdfn errors:

Error codes

Common issues

Cannot connect to pdfn server

The dev server isn’t running. Start it in a separate terminal:

PDF generation timed out

Simplify your template or increase the timeout:

Invalid API key

Check that PDFN_API_KEY is set correctly in your environment. Keys start with pdfn_test_ or pdfn_live_. Get a new key at console.pdfn.dev.

render() called in the browser

render() uses react-dom/server which isn’t available in browsers. In Next.js, make sure this code runs in a Server Component or API route — not a Client Component.

Local fonts or images on edge runtimes

Edge runtimes (Vercel Edge, Cloudflare Workers) can’t read local files. Options:
  • Use Google Fonts instead of local font files
  • Use remote URLs for images instead of local paths
  • Pre-encode assets as base64 data URIs
  • Switch to Node.js runtime (Vercel Serverless instead of Edge)

Client components not rendering

Templates that use "use client" components (like chart libraries) need a build plugin. Make sure @pdfn/next or @pdfn/vite is installed and configured:
See Next.js for details.

React component threw during render

Common causes:
  • Using async components (not supported in static rendering)
  • Component threw an error during render
  • Invalid React element passed to render()
Check your template renders correctly in npx pdfn dev before calling generate().

Next steps

Components

Document, Page, and layout components

Generate & Render

Client setup, generate() and render() parameters