Automate

JavaScript SDK

@pdfforge/core — the official TypeScript client.

@pdfforge/core is the official TypeScript client: typed methods for every main endpoint, automatic retries, binary handling done for you. Runs on Node.js 18+ and edge runtimes (uses fetch).

Install & configure

npm install @pdfforge/core
import { PDFForge } from "@pdfforge/core";

// Simple: just the key
const client = new PDFForge(process.env.PDFFORGE_API_KEY!);

// Full config
const client2 = new PDFForge({
  apiKey: process.env.PDFFORGE_API_KEY!,
  baseURL: "https://api.pdf-forge.dev", // default
  timeout: 60_000,                       // ms, default 60s
  retries: 2,                            // transient failures, default 2
});

The key must start with pf_live_ or pf_test_ — anything else throws at construction.

Generation

// HTML → PDF
const pdf = await client.html("<h1>Report</h1>", { format: "A4" });

// URL → PDF
const page = await client.url("https://example.com", { printBackground: true });

// Stored template + data → PDF
const invoice = await client.template("invoice", { number: "2026-001" });

All three return a PDFResult:

interface PDFResult {
  buffer: Uint8Array; // the PDF bytes
  pages: number;      // from X-PDF-Pages
  size: number;       // from X-PDF-Size
  duration: number;   // from X-Generation-Time-Ms
}

Operations

const merged = await client.merge([pdfA, pdfB]);   // Uint8Array[] → PDFResult
const split = await client.split(pdf);             // → { pages: Uint8Array[], pageCount }

Resources

ResourceMethods
client.templateslist(), create(params), get(id), update(id, params), delete(id)
client.pdfTemplateslist(), get(id), create({ name, pdf, variables }), render(id, variables)
client.pdfperceive(pdf, options), editText(pdf, edits), redact(pdf, regions), annotate(pdf, objects), stripWatermark(pdf, minFont?), toImage(pdf, options), restamp(pdf, replacements), fromImages(images)
client.jobslist(), get(id), waitFor(id, { intervalMs, maxAttempts })

The client.pdf resource is the PDF toolkit: perceive first, then act by element id or bbox. Operations without an SDK method yet (compress, protect, form fill...) are one fetch away — see their doc pages for the exact bodies.

Error handling

Non-2xx responses throw a PDFForgeError carrying the API's structured error:

import { PDFForge, PDFForgeError } from "@pdfforge/core";

try {
  await client.html("");
} catch (e) {
  if (e instanceof PDFForgeError) {
    console.error(e.code, e.message); // e.g. "invalid_request", "The 'html' field is required"
  }
}

Transient failures are retried automatically (retries, default 2). Error codes are listed in Errors & limits.

Next steps

On this page