Create and modify PDF documents in any JavaScript environment.
open sourceMITself-hostablefree
pdf-lib is a TypeScript library, compiled to pure JavaScript with no native dependencies, that creates new PDFs and edits existing ones in browsers, Node, Deno and React Native. It can draw text, images and SVG paths, embed fonts and pages from other PDFs, add, remove, split and merge pages, and create, fill, read and flatten AcroForm fields (text, checkboxes, radio groups, dropdowns, option lists). Unlike most JS PDF libraries it focuses on modifying documents you already have. It cannot open encrypted PDFs, and the last release (1.17.1) was in November 2021. Cantoo maintains a fork with the same API, @cantoo/pdf-lib.
Problems it solves
- fill in the fields of an existing PDF form from JavaScript without a server round trip
- I need to stamp a name and date onto page 1 of a PDF the user uploads, right in the browser
- merge several PDFs into one file in Node without shelling out to a command-line tool
- my React app has a fillable PDF and I want to set the checkbox and text field values programmatically
- flatten a filled-in form so people cannot edit the answers afterwards
- add a watermark or page numbers to every page of a PDF someone else made
- split a big PDF into separate files per page in a Cloudflare Worker or Lambda
- read which values are already filled in on a PDF form
- embed a custom TTF font and a PNG logo into an existing document
- copy pages from one PDF into another and reorder them
- need a PDF editing library with zero native dependencies that also runs in Deno and React Native
- turn a plain PDF into a fillable one by adding text fields and checkboxes from code
Features
- Create PDFs from scratch or modify existing ones
- Draw text, images and SVG paths
- Embed TrueType/OpenType fonts and PNG/JPEG images; measure text
- Embed and draw pages from other PDFs
- Add, insert, remove, split and merge pages
- Create, fill, read and flatten AcroForm fields (text, checkbox, radio, dropdown, option list)
- File attachments and document metadata
- No native dependencies
Limitations
- Doesn't open or edit encrypted PDFs: PDFDocument.load throws an EncryptedPDFError1
- Doesn't extract plain text from a page outside form fields: it reads the values of text fields only1
Capabilities
| Has official SDKs | plan not known |
|---|
Forks
- @cantoo/pdf-lib An actively maintained fork of pdf-lib: create and modify PDF documents in any JavaScript environment. Its own project since 2021.
- @pdfme/pdf-lib This version is forked from Hopding/pdf-lib, with several bug fixes and additional features. 3 changes.
Alternatives
The same job
These do what pdf-lib does.
- HexaPDF Versatile PDF creation and manipulation for Ruby
- pdfcpu PDF tooling for Go and the command line
- DocSpring Fill PDF forms, generate PDFs and Word documents, and collect e-signatures with one API.
- pdftk (PDFtk Server and pdftk-java) A command-line tool for working with PDFs
- Apache PDFBox The Apache PDFBox library is an open source Java tool for working with PDF documents.
- @cantoo/pdf-lib An actively maintained fork of pdf-lib: create and modify PDF documents in any JavaScript environment
