Free pdfmake Templates & Visual docDefinition Builder

Declarative JSON docDefinition engine that compiles to PDFKit streams with automatic multi-page table pagination (189 ms & 165.5 KB across 27 pages; 4.4 ms single-page). Works in Node.js (PdfPrinter) and browsers (vfs_fonts.js).

Install: npm install pdfmake@^0.2.12 | Runtime: Node.js (TypeScript / JSON) | Version: 0.2.12 | Popularity: 3.1M/mo installs

Works with: Node.js, Browser, Angular, React, Vue, Express

How pdfmake Templates Work in CodePDF

pdfmake consumes a declarative JSON tree (docDefinition with content, styles, columns, stack, and table bodies). CodePDF translates visual components, typography, and dynamic array bindings directly into structured pdfmake definitions.

  • Replaces manual JSON nesting and [left, top, right, bottom] margin guesswork with drag-and-drop visual editing
  • Generates structured table definitions with typed dynamic row arrays and styled headers
  • Works identically in browser downloads (pdfMake.createPdf(dd).download()) and Node.js PdfPrinter streams

Quick Start: Generate PDFs with pdfmake

Install pdfmake (TypeScript / JSON), then run the code CodePDF exports for any template:

npm install pdfmake@^0.2.12

  1. Install pdfmake: npm install pdfmake@^0.2.12
  2. Save the generated file as generateDocument.ts in your project.
  3. Call generatePDF() in a browser context, or use pdfmake's server-side API for Node.js.
  4. For Node.js: use const PdfPrinter = require('pdfmake'); and call buildDocDefinition() to get the doc object.

Example pdfmake Output (Standard B2B Commercial Invoice)

Compiled directly from the Standard B2B Commercial Invoice template (TypeScript / JSON):

import pdfMake from 'pdfmake/build/pdfmake';
import pdfFonts from 'pdfmake/build/vfs_fonts';

// This code is generated using codepdf.dev

// @ts-ignore
pdfMake.vfs = pdfFonts.pdfMake ? pdfFonts.pdfMake.vfs : pdfFonts;

interface DocumentData {
  vendorCompany: string;
  invoiceNumber: string;
  vendorAddress: string;
  invoiceDate: string;
  paymentDueDate: string;
  grandTotalNum: number;
  clientCompany: string;
  clientDetails: string;
  lineItems: Array<Record<string, string>>;
  wireBank: string;
  paymentTerms: string;
  subtotalAmount: string;
  taxAmount: string;
  grandTotal: string;
  paymentMethods: string[];
}

export const SAMPLE_DATA: DocumentData = {
  vendorCompany: 'MERIDIAN CLOUD INFRASTRUCTURE LLC',
  invoiceNumber: 'INV-2026-8842',
  vendorAddress: '100 Montgomery St, Suite 2400, San Francisco, CA 94104 · EIN: 84-2938192',
// … (702 more lines in full generated file)

Custom Fonts in pdfmake

Pass a font dictionary mapping normal, bold, italics, and bolditalics weights to TTF paths into PdfPrinter.

  1. Define each custom family with normal, bold, italics, and bolditalics keys pointing to .ttf files.
  2. Instantiate new PdfPrinter(fonts) on Node.js or assign pdfMake.fonts + pdfMake.vfs in browsers.
  3. Set defaultStyle: { font: '{{FONT_FAMILY}}' } in the document definition.

Official documentation: pdfmake docs

pdfmake Benchmark Results

Measured on CodePDF’s 26-component, 27-page All-Components Dynamic Multi-Page Flow Stress Test (same document across all 22 libraries).

pdfmake stress-test results and rank out of 22 PDF libraries
MetricpdfmakeRank (of 22)
Wall-clock time189 ms11th fastest
CPU time0.85 s13th lowest
Peak RAM183.7 MB16th lowest
PDF file size165.5 KB14th smallest
Engine type
Custom Layout Engine
Under the hood
Declarative JSON docDefinition tree compiled to PDFKit vector streams
Runs in
Node.js (PdfPrinter), Browser (vfs_fonts.js)
Verdict
Declarative JSON tables & automatic pagination in 189 ms (27p, 165.5 KB; 4.4 ms single-page); VFS fonts add weight to browser bundles.

Under the Hood & Benchmark Highlights

  • Turns a plain JSON tree (docDefinition) into paginated PDFs using PDFKit under the hood — no HTML, no JSX, and automatic multi-page table splitting.
  • Generated 12 pages across all 26 components in 1.48s (121.4 KB PDF, ~237 MB RAM).
  • Watch the client/server split: browsers require virtualized vfs_fonts.js bundles (heavier JS download), while Node.js reads .ttf files directly via PdfPrinter.

Good to Know (pdfmake Caveats)

  • Different font setup in Browser vs. Node.js: Browsers require a virtual file system bundle (vfs_fonts.js), whereas Node.js uses PdfPrinter(fonts) with filesystem .ttf paths.
  • JSON tree, not HTML: Styling uses pdfmake's own style dictionaries and [left, top, right, bottom] margin arrays rather than CSS.
  • Client bundle size: Bundling pdfmake with full Roboto VFS fonts adds substantial weight to browser JS bundles; prefer Node.js server rendering for high-traffic web apps.

Popular pdfmake PDF Templates

All 100 CodePDF templates export to pdfmake. Browse them by category: Career (5) · Business (6) · Education (7) · Marketing (6) · Human Resources (8) · Finance (7) · Legal (8) · Healthcare (10) · Logistics (6) · Real Estate (6) · Hospitality (4) · Operations (5) · Technology (5) · Banking (9) · Non-Profit (4) · Personal (3) · Compliance & Enterprise (1), or see the full template gallery.

pdfmake Template FAQs

Is CodePDF an alternative to the online pdfmake playground?

Yes — CodePDF gives you a full Figma-like drag-and-drop canvas, live data-model bindings, and 100 starter templates that compile directly into clean pdfmake TypeScript/JavaScript docDefinition code.

Can pdfmake templates run on both client and server?

Yes. The same exported docDefinition object works in the browser with pdfmake/build/pdfmake and on Node.js servers with PdfPrinter.

How are dynamic line-item arrays bound in pdfmake exports?

Array-bound tables and lists compile into clean .map() transformations over your typed input data object inside table.body.

pdfmake vs Other Node.js PDF Libraries

  • @react-pdf/renderer — 1.06 s, 237.3 MB RAM, 126.8 KB PDF. #2 smallest multi-page PDF overall (126.8 KB across 18p; 12 ms single-page, 1.06s stress) with Yoga Flexbox; run server-side in Next.js.
  • pdf-lib — 334 ms, 209.7 MB RAM, 203.8 KB PDF. Runs in browsers & Edge Workers and edits/merges existing PDFs (5.3 ms single-page; 334 ms / 203.8 KB across 20p).
  • jsPDF — 120 ms, 98.3 MB RAM, 157.4 KB PDF. Fastest Node.js/browser JS engine in stress test (120 ms for 22p, 3.5 ms single-page, 98.3 MB RAM); custom TTFs require base64 VFS.
  • PDFKit (Node.js) — 140 ms, 125.5 MB RAM, 162.6 KB PDF. Fastest server-only Node.js stream writer on single-page invoices (2.8 ms / 2.6 KB; 140 ms / 125.5 MB RAM across 22p).
  • Puppeteer — 1.35 s, 263.2 MB RAM, 841.2 KB PDF. Full Chrome CSS fidelity, but 841.2 KB PDF (#2 largest), 263.2 MB RAM (highest), 1.35s warm render (+ cold Chrome launch & ~350 MB binary).
  • Playwright — 883 ms, 203.8 MB RAM, 452.2 KB PDF. Beat Puppeteer on pure PDF render speed (883 ms vs 1.35s), RAM (204 vs 263 MB), and PDF size (452 vs 841 KB); Chromium-only.
  • HTML5 & CSS Paged Media — 818 ms, 196.3 MB RAM, 453.6 KB PDF. Renderer-agnostic HTML5 + @page CSS; warm Chromium print finishes 19 pages in 818 ms (453.6 KB; 581 ms single-page).

See the full 22-library benchmark rankings · Compare all supported PDF libraries