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 14 apps in this directory
Activepieces
Automation · AI Assistants
Open-source AI automation platform that converts 280+ workflow integrations into MCP servers for LLMs, with no-code builders and TypeScript extensibility.
AFFiNE
Productivity · Project Management · Note Taking
Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.
AnythingLLM
Developer Tools · Automation · AI Assistants
The all-in-one AI platform for private document chat, no-code agents, and local LLMs with zero setup friction.
Cherry Studio
AI Assistants
All-in-one AI desktop client with 300+ assistants and multi-model support
fountain-ink
Blogging
A self-hostable, decentralized blogging platform built on Lens Protocol — own your content, audience, and distribution forever.
Huly Platform
Project Management · Team Chat · Collaboration
Open-source all-in-one workspace that replaces Linear, Jira, Slack, and Notion for product and engineering teams.
Joplin
Note Taking
The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.
Kibana
Analytics · Monitoring
Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.
Litlyx
Analytics
Cookie-free, AI-powered web analytics you can self-host in 30 seconds with Docker.