PDF4.dev
Quickstart

Node.js

Prerequisites

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.

render.js
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");
Run
node render.js

3. 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