Developer quickstart

Generate PDFs in Node.js and TypeScript

Call the synchronous REST endpoint with the built-in fetch API and save the binary response.

Prerequisites

  • A PDFDesignAPI account and API token.
  • A template UUID with a schema and at least one data binding.
  • Trusted server-side code where the token remains secret.

Generate and save the PDF

import { writeFile } from 'node:fs/promises'

const response = await fetch(
  `https://pdfdesignapi.com/api/v1/generate/single/${process.env.TEMPLATE_UUID}`,
  {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.PDFDESIGNAPI_TOKEN}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      data: { customer: { name: 'Example BV' } },
    }),
  },
)

if (!response.ok) {
  throw new Error(`PDF generation failed: ${response.status} ${await response.text()}`)
}

await writeFile('document.pdf', Buffer.from(await response.arrayBuffer()))

Production notes

  • Run this only in trusted server code.
  • For an HTTP response, stream the PDF rather than buffering very large files.
  • Use the async job endpoint when generation should not hold open an interactive request.
Validate payloads →Use async jobs →Create a free account →