Quickstart
Node.js
Prerequisites
- A PDF4.dev account — sign up free
- An API key from Settings
- Node.js 18+
1. Create a template
Go to the dashboard and click New template. Pick a starter (Invoice, Receipt, Certificate...) or start blank.
Note the template ID or slug from the editor URL: /dashboard/templates/tmpl_xxx.
2. Render a PDF
No SDK needed — the API is a simple HTTP POST that returns a PDF binary.
import { writeFileSync } from "node:fs";
const response = await fetch("https://pdf4.dev/api/v1/render", {
method: "POST",
headers: {
Authorization: "Bearer p4_live_your_key_here",
"Content-Type": "application/json",
},
body: JSON.stringify({
template_id: "invoice",
data: {
company_name: "Acme Corp",
invoice_number: "INV-2025-001",
total: "$4,500.00",
},
}),
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.error.message);
}
const buffer = Buffer.from(await response.arrayBuffer());
writeFileSync("invoice.pdf", buffer);
console.log("PDF saved to invoice.pdf");node render.js3. Pass dynamic data
Any {{variable}} in your template can be replaced at render time via the data object:
body: JSON.stringify({
template_id: "invoice",
data: {
customer_name: "Jane Smith",
due_date: "2025-06-30",
line_items: "...",
},
}),4. Render raw HTML (no template)
Skip templates entirely for one-off documents:
body: JSON.stringify({
html: "<h1>Hello {{name}}</h1>",
data: { name: "World" },
}),Next steps
- Using with Next.js — server action and API route examples
- PDF format — page size, margins, custom dimensions
- API reference — full render endpoint docs