ScriptsMay 30, 2026·3 min read

pdfmake — Client-Server PDF Generation for JavaScript

Create complex PDF documents in the browser or Node.js using a declarative document-definition object.

Agent ready

Safe staging for this asset

This asset is staged first. The copied prompt tells the agent to inspect the staged files and ask before activating scripts, MCP config, or global config.

Stage only · 29/100Policy: stage
Agent surface
Any MCP/CLI agent
Kind
CLI Tool
Install
Single
Trust
Trust: Established
Entrypoint
pdfmake Overview
Safe staging command
npx -y tokrepo@latest install 841b0f12-5c02-11f1-9bc6-00163e2b0d79 --target codex

Stages files first; activation requires review of the staged README and plan.

Introduction

pdfmake is a JavaScript library for generating PDF documents on both client and server side. Instead of manually positioning elements on a page, developers describe documents with a declarative JSON-like definition, and pdfmake handles layout, pagination, and rendering automatically.

What pdfmake Does

  • Generates multi-page PDF documents from declarative JavaScript objects
  • Runs identically in the browser (no server round-trip) and in Node.js
  • Handles automatic page breaks, headers, footers, and page numbering
  • Supports tables with column spans, row spans, and auto-width calculations
  • Embeds custom fonts, images (including SVG), and vector graphics

Architecture Overview

pdfmake consists of a layout engine and a PDF writer. The layout engine takes a document-definition object, measures text runs using font metrics, calculates column and row dimensions for tables, and determines page breaks. The PDF writer then serializes the laid-out nodes into a valid PDF byte stream. In the browser, it uses an in-memory virtual file system for font files; in Node.js, it reads fonts from disk. The output can be returned as a buffer, base64 string, or piped to a writable stream.

Self-Hosting & Configuration

  • Install via npm for Node.js projects or load the CDN build for browser use
  • Register custom fonts by providing TTF files through the virtual file system API
  • Configure default styles, page size (A4, Letter, custom), and margins in the document definition
  • Use the Node.js buffer output for server-side generation and HTTP response streaming
  • No external dependencies beyond the bundled font files

Key Features

  • Declarative API eliminates manual coordinate math and page management
  • Full table support with automatic column width calculation and nested tables
  • Watermarks, backgrounds, headers, and footers with page-aware content
  • Client-side generation keeps data private and reduces server load
  • Consistent rendering across browser and Node.js environments

Comparison with Similar Tools

  • jsPDF — imperative API with manual positioning; pdfmake offers declarative layout
  • PDFKit — powerful low-level Node.js library; pdfmake adds automatic pagination and table layout
  • Puppeteer/Playwright — render HTML to PDF via a headless browser; pdfmake generates PDFs natively without a browser engine
  • WeasyPrint — Python HTML-to-PDF; pdfmake is JavaScript-native and runs client-side
  • React-PDF — React component for rendering PDFs; pdfmake is framework-agnostic

FAQ

Q: Can pdfmake run in the browser without a server? A: Yes. The entire PDF is generated client-side in JavaScript. No server communication is needed.

Q: How do I use custom fonts? A: Convert TTF files to a virtual file system module using the provided build tool, then register them in the fonts configuration.

Q: Does it support right-to-left text? A: Basic RTL support exists, but complex scripts like Arabic may need careful font selection and testing.

Q: What is the maximum document size? A: There is no hard limit. Performance depends on available memory; documents with thousands of pages work in Node.js but may be slow in browsers.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets