Authoring · Node.js and TypeScript

Generate a PDF in Node.js

Create PDFs programmatically from Node.js: pages, vector graphics, embedded and subset fonts with full Unicode shaping, justified paragraphs, tables and images. rust-pdf gives Node.js a fast, memory-safe core with deterministic output.

Last updated: 2026-06-29

Why Node.js and TypeScript needs this

Building a PDF in Node has long meant rendering HTML in headless Chrome, a slow, memory-hungry dependency that drifts visually and never produces archival-grade output.

Generation is the free foundation. Draw shapes, place shaped and kerned Unicode text, lay out wrapping paragraphs, embed JPEG and PNG images, and add links and bookmarks. Output is deterministic (the same input yields the same bytes), which makes it auditable and testable.

Wire new Document() into an Express or NestJS endpoint to build invoices and reports on the fly, returning the document from the route. The package ships TypeScript types in index.d.ts so every drawing call autocompletes, and the pure-FFI Koffi binding installs from npm with no node-gyp, replacing a Puppeteer step with one small native dependency.

  • Vector graphics, embedded and subset fonts, HarfBuzz-quality Unicode shaping and kerning.
  • Wrapping and justified paragraphs, tables, images (JPEG, PNG, alpha, 16-bit).
  • Deterministic output: identical bytes for identical input, ideal for audits and tests.

Generate a PDF in Node.js with rust-pdf

Install from npm, then create a Document, add a page and draw. The snippet below is real Node.js from the reference docs.

npm install rustpdf

Node.js
const { Document } = require("rustpdf");

const doc = new Document();              // A4 by default
doc.addPage();
doc.setFillRgb(0.86, 0.20, 0.18);
doc.rect(72, 640, 200, 120);             // x, y, width, height (points)
doc.fill();
doc.save("out.pdf");
doc.close();
Validated by: qpdfmutool

All of this basic generation is part of the free tier in Node.js — no license token needed.

The full Node.js authoring reference is in the documentation.

Generation in Node.js: FAQ

Is generating PDFs free in Node.js?

Yes. All basic generation (pages, graphics, fonts, text, paragraphs, images, links, bookmarks, watermarks) is free forever. You only license corporate features such as PDF/A, signatures and encryption when you ship them.

Does it support Unicode and custom fonts?

Yes. Fonts are embedded and subset with HarfBuzz-quality shaping and kerning, using Type0 fonts with ToUnicode, so non-Latin scripts render and extract correctly.

Why a Rust core for Node.js?

A thin idiomatic binding exposes one memory-safe, high-performance Rust core to Node.js. You get the same engine, the same features and deterministic output, without a heavy runtime.

Can rust-pdf replace Puppeteer for generating PDFs in Node?

For programmatic documents, yes. Instead of rendering HTML in headless Chrome you draw pages, text and tables directly, which is faster, deterministic and far lighter in memory. The Koffi binding installs from npm with no node-gyp, so there is no browser to bundle or keep patched.

Render PDFs from code instead of a browser

One Rust core, the same deterministic output in every language. Generation is free; license PDF/A, signatures or encryption only when you ship them.