pdf-lib
Create and modify PDF documents in any JavaScript environment, from Node to the browser
Repository Health
Technical Analysis
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
PDFDocumentAPI 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
Magic
AI Agents · Automation · Low Code Platforms
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.
open-design
Design Tools
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.
OpenSign
Digital Signiture
Self-host a full-featured DocuSign alternative with unlimited e-signatures, multi-signer workflows, and cryptographic PDF signing.
Papermark
Digital Signiture · File Storage
Open-source DocSend alternative with page-by-page analytics, secure data rooms, and custom domains for document sharing.
Suna
AI Agents
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.
twenty
CRM
The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.