Generate certificate PDFs in Node.js

The simplest way to generate certificate PDFs in Node.js is to POST a certificate HTML template and a JSON data object to the Docweave API — Docweave binds the recipient name, course title, issue date, and issuer into the template and hands back a finished PDF, with no headless browser for you to install or run.

Certificate template

Any HTML works as a template. Use {{ placeholders }} for the recipient name, course or award title, issue date, and issuer:

<article style="font-family: 'Georgia', serif; text-align:center; padding:64px; border: 8px double #c9a227;">
  <p style="letter-spacing:4px; text-transform:uppercase; color:#8a6d00; font-size:13px;">
    Certificate of Completion
  </p>

  <h1 style="margin:24px 0 8px; font-size:36px; color:#1a1a1a;">{{ recipient_name }}</h1>
  <p style="color:#555; font-size:16px;">has successfully completed</p>

  <h2 style="margin:16px 0; font-size:24px; color:#1a1a1a;">{{ course_title }}</h2>

  <div style="margin-top:56px; display:flex; justify-content:space-between; padding:0 40px;">
    <div style="text-align:left;">
      <p style="border-top:1px solid #999; padding-top:6px; margin:0;">{{ issue_date }}</p>
      <p style="color:#777; font-size:12px; margin:2px 0 0;">Date issued</p>
    </div>
    <div style="text-align:right;">
      <p style="border-top:1px solid #999; padding-top:6px; margin:0;">{{ issuer }}</p>
      <p style="color:#777; font-size:12px; margin:2px 0 0;">Issued by</p>
    </div>
  </div>
</article>

Generate the PDF from Node.js

Use the built-in fetch to POST the template and data to /api/v1/pdf, then save the raw response bytes with node:fs/promises:

import { writeFile } from "node:fs/promises";

const template = `<article style="font-family: 'Georgia', serif; text-align:center; padding:64px; border: 8px double #c9a227;">
  <p style="letter-spacing:4px; text-transform:uppercase; color:#8a6d00; font-size:13px;">
    Certificate of Completion
  </p>

  <h1 style="margin:24px 0 8px; font-size:36px; color:#1a1a1a;">{{ recipient_name }}</h1>
  <p style="color:#555; font-size:16px;">has successfully completed</p>

  <h2 style="margin:16px 0; font-size:24px; color:#1a1a1a;">{{ course_title }}</h2>

  <div style="margin-top:56px; display:flex; justify-content:space-between; padding:0 40px;">
    <div style="text-align:left;">
      <p style="border-top:1px solid #999; padding-top:6px; margin:0;">{{ issue_date }}</p>
      <p style="color:#777; font-size:12px; margin:2px 0 0;">Date issued</p>
    </div>
    <div style="text-align:right;">
      <p style="border-top:1px solid #999; padding-top:6px; margin:0;">{{ issuer }}</p>
      <p style="color:#777; font-size:12px; margin:2px 0 0;">Issued by</p>
    </div>
  </div>
</article>`;

const response = await fetch("https://docweave.dev/api/v1/pdf", {
  method: "POST",
  headers: {
    Authorization: "Bearer dw_live_your_key",
    "Content-Type": "application/json",
    Accept: "application/pdf",
  },
  body: JSON.stringify({
    source: {
      type: "template",
      template,
      data: {
        recipient_name: "Jamie Rivera",
        course_title: "Advanced TypeScript Patterns",
        issue_date: "July 16, 2026",
        issuer: "Docweave Academy",
      },
    },
    idempotencyKey: "cert-jamie-rivera-advanced-ts",
  }),
});

if (!response.ok) {
  throw new Error(`Docweave returned ${response.status}`);
}

const bytes = Buffer.from(await response.arrayBuffer());
await writeFile("certificate.pdf", bytes);

…or from an AI agent

An AI agent can generate the same certificate without writing any HTTP code. Run npx @docweave/mcp to add the Docweave MCP server, and the agent gets a generate_pdf tool that wraps the same orchestration:

// From an AI agent over MCP — no HTTP plumbing:
// npx @docweave/mcp
generate_pdf({
  source: {
    type: "template",
    template: "<h1>{{ recipient_name }}</h1><p>{{ course_title }}</p>",
    data: { recipient_name: "Jamie Rivera", course_title: "Advanced TypeScript Patterns" }
  },
  outputPath: "/tmp/certificate.pdf"
})

FAQ

How do I generate a certificate PDF in Node.js?

POST to /api/v1/pdf with a source of type "template": pass your certificate HTML with {{ placeholders }} and a data object with the recipient name, course or award title, issue date, and issuer. Docweave binds the JSON into the template and returns the certificate PDF as raw bytes.

Do I need Puppeteer or Playwright installed to generate certificates?

No. Docweave runs Chromium on its own infrastructure and returns a finished PDF over HTTP. Your Node.js code only needs fetch (built into modern Node) and node:fs/promises to save the response — no browser binary to install or manage.

How do I avoid generating a duplicate certificate for the same recipient?

Include an idempotencyKey, for example a string combining the recipient and course. A repeat request with the same key returns the stored result instead of re-rendering or re-billing, so retries after a network error are always safe.

How is certificate PDF generation priced?

Pricing is per document, not per page. A single-page certificate is billed the same as any other document, so generating certificates in bulk for a graduating class or course cohort doesn't cost extra per page.

Related

Ready to generate certificate PDFs in production?

Get an API key