pdf-lib

Create and modify PDF documents in any JavaScript environment, from Node to the browser

Library
npm
v1.17.1
8,666 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
50 /100 Fair
Development Activity 0
Maintenance 32
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
77 /100 Good
Architecture 78
Code Quality 72
Innovation 75
Learning Curve 82

pdf-lib is a pure JavaScript/TypeScript library for creating and modifying PDF documents without relying on native dependencies or a headless browser. Unlike most JavaScript PDF tools that can only generate new documents from scratch, pdf-lib can load and edit existing PDFs — adding pages, filling and flattening forms, embedding images and fonts, and drawing text or vector graphics directly onto pages.

Because it has zero native bindings, pdf-lib runs identically in Node.js, browsers, Deno, and React Native, making it a common choice for client-side PDF generation and for serverless environments where installing tools like wkhtmltopdf or a headless Chrome instance is impractical.

What You Get

  • A PDFDocument API to create new PDFs or load and modify existing ones
  • Full AcroForm support: create, fill, and flatten form fields (text, checkboxes, radio groups, dropdowns, option lists)
  • Page manipulation: add, insert, remove, and copy pages between documents
  • Drawing primitives for text, images (PNG/JPEG), vector graphics, and SVG paths
  • Standard and custom font embedding with Unicode (UTF-8/UTF-16) support
  • Document metadata and viewer-preference reading/writing, plus attachment embedding
  • Runs with zero native dependencies in Node, browsers, Deno, and React Native

Common Use Cases

  • Filling and flattening PDF forms server-side for contracts, applications, or tax documents
  • Generating invoices, receipts, or reports entirely in the browser without a backend
  • Merging or splitting existing PDFs by copying pages between documents
  • Watermarking or stamping existing PDFs with text, images, or SVG graphics
  • Programmatically embedding attachments or updating document metadata in a document pipeline

Under The Hood

Architecture — pdf-lib is organized around a layered API in src/: api/ exposes the high-level, user-facing classes (PDFDocument, PDFPage, PDFForm and field types under api/form/, PDFFont, PDFImage), while core/ implements the low-level PDF object model (dictionaries, streams, xref tables, the document parser/writer) that the API layer manipulates. PDFDocument acts as the central mutable in-memory representation: PDFDocument.load() parses an existing file’s object graph into this model, create() builds one from scratch, and save() serializes it back to bytes — the same representation drives editing and creation through one code path.

Tech Stack — Written in TypeScript, built with Rollup into CJS, ESM, and UMD bundles (plus a downlevel-dts pass for older TypeScript consumers) so it can be imported directly in Node, bundled for the browser, or loaded via <script> tag. It has no runtime dependencies on native binaries or headless browsers — the entire PDF object model and rendering-primitive logic is implemented in pure JS/TS, which is what allows identical behavior across Node, browsers, Deno, and React Native.

Code Quality — Tests live under tests/ as Jest specs (tests/api/*.spec.ts, plus dedicated suites for forms and text handling) run via jest --config jest.json --runInBand, with fixture PDFs used to assert against known-good outputs. The codebase enforces tslint and prettier in its lint scripts, and TypeScript’s tsc --noEmit is run as a standalone typecheck step. The project has been effectively feature-complete since ~2021, with recent commit activity dropping to near zero, so open issues around edge-case encodings/newer PDF spec features can persist longer than in an actively maintained project.

API Design — The PDFDocument/PDFPage/PDFForm object-oriented surface reads close to a document-editing DSL (pdfDoc.addPage(), page.drawText(...), form.getTextField(...).setText(...)), keeping common operations to a handful of chained calls. Every public method and class is documented with TSDoc comments that ship in the published types, and the README’s example-driven structure (create/modify/fill/flatten/copy, each with a live JSFiddle demo) makes the learning curve shallow for common tasks, though deeper PDF-spec concepts (encryption, low-level object references) require reading core/ directly.

Used by 15 apps in this directory

TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,055

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
68
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 2 months ago
TypeScript
72%
Apache 2.0

open-design

Design Tools

103,625

Local-first, open-source Claude Design alternative that turns your existing coding agent CLI into a full agentic design studio — with 259+ skills, 142+ design systems, and sandboxed artifact delivery across web, desktop, and mobile surfaces.

View details
85
Repo Health
86
Technical
72
Dependency
Built with
TypeScript 72%
HTML 21%
Updated 2 days ago
JavaScript
90%
Other

OpenSign

Digital Signiture

7,163

Self-host a full-featured DocuSign alternative with unlimited e-signatures, multi-signer workflows, and cryptographic PDF signing.

View details
83
Repo Health
61
Technical
69
Dependency
Built with
JavaScript 90%
Updated 3 days ago
TypeScript
99%
Other

Papermark

Digital Signiture · File Storage

9,263

Open-source DocSend alternative with page-by-page analytics, secure data rooms, and custom domains for document sharing.

View details
78
Repo Health
63
Technical
66
Dependency
Built with
TypeScript 99%
Updated 1 months ago
TypeScript
92%
Other

Suna

AI Agents

20,306

Turn your company into a git repo — one config, one command center, a workforce of AI agents that runs the real work around the clock.

View details
90
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 92%
Updated 2 days ago
TypeScript
84%
Other

twenty

CRM

59,615

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 84%
MDX 14%
Updated 3 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers