Skip to main content
The pdfnoodle package is a TypeScript-first Node.js SDK with zero runtime dependencies. It uses native fetch (Node.js 20+) and ships as both ESM and CommonJS.

Installation

Setup

You can also set the PDFNOODLE_API_KEY environment variable and omit the constructor argument:

Response Pattern

Every method returns a { data, error } object. When the request succeeds, data contains the result and error is null. When it fails, data is null and error contains the error details.
This pattern makes it impossible to forget error handling — you always destructure both values.

PDFs

The Pdf service generates PDFs from raw HTML or from reusable templates. Both sync methods include automatic polling — if the API takes longer than 30 seconds to render, the SDK polls the status endpoint with exponential backoff until the PDF is ready. No extra code needed. Methods available:

Generate PDF from HTML

Use pdf.fromHTML() to convert raw HTML into a PDF. The API renders the HTML with a headless browser and returns a temporary signed URL to download the file.
What happens under the hood:
  1. The SDK sends a POST to /v1/html-to-pdf/sync with your HTML and PDF parameters
  2. If the API responds with 200, the signed URL is returned immediately
  3. If it responds with 202 (rendering took >30s), the SDK automatically polls /v1/pdf/status/:requestId with exponential backoff until the PDF is ready
If you prefer to handle the result asynchronously via a webhook instead of waiting, use fromHTMLAsync() with a webhook field — you’ll get a requestId back immediately and the result will be POSTed to your URL when ready.

Generate PDF from Template

Use pdf.fromTemplate() when you have a reusable template created in the Template Builder. You pass the template ID and the dynamic data — the API merges them and returns the PDF. This is ideal for documents you generate repeatedly with different data (invoices, receipts, certificates, reports).
What happens under the hood:
  1. The SDK sends a POST to /v1/pdf/sync with your template ID and data
  2. The API renders the template using Handlebars syntax, replacing {{invoice_number}}, {{#each items}}, etc. with your values
  3. Same auto-polling behavior as fromHTML() if rendering exceeds 30 seconds
Not sure which variables your template expects? Use pdfnoodle.templates.getVariables(templateId) to get the schema — see the Templates section below.

Templates

The Templates service lets you manage your reusable PDF templates programmatically. You can create templates using AI, list existing ones, fetch their details, and inspect their variable schemas. Methods available:

Create a template with AI

The create() method uses AI to generate a template from a natural language description. Template creation is asynchronous — the method returns a templateId immediately, and the template is ready after about 2 minutes.

Tools

The Tools service provides PDF utility operations — merging, splitting, compressing, converting Markdown, and updating metadata. Each tool accepts a publicly accessible PDF URL and returns a new signed URL with the result. Methods available:

Merge multiple PDFs

Combine multiple PDF files into a single document. The PDFs are merged in the order you provide them.

Polling Options

The fromHTML() and fromTemplate() methods accept an optional second argument to configure polling behavior when the API returns a 202:

Cancelling a long-running generation


Error Codes


Resources