# @cantoo/pdf-lib

> An actively maintained fork of pdf-lib: create and modify PDF documents in any JavaScript environment

Source: https://talira.ai/catalog/cantoo-pdf-lib-2fgqrykx
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library
- Categories: [documents / pdf / manipulation](https://talira.ai/categories/documents/pdf/manipulation), [documents / pdf / forms](https://talira.ai/categories/documents/pdf/forms), [languages / javascript](https://talira.ai/categories/languages/javascript)
- Licence: MIT[^2]
- Pricing: Free and open source[^2]
- Free tier: yes[^2]
- Self-hostable: yes[^1]
- Backed by: [Cantoo](https://talira.ai/orgs/cantoo.md)
- Forked from [pdf-lib](https://talira.ai/catalog/pdf-lib-80dtat8x.md) in 2021. Cantoo maintains it for its own product and ships features upstream doesn't provide; pdf-lib's owner stopped answering, so Cantoo asks for issues and pull requests on the fork

@cantoo/pdf-lib is Cantoo's actively maintained fork of [pdf-lib](https://talira.ai/catalog/pdf-lib-80dtat8x.md), the pure JavaScript library that creates and edits PDFs in browsers, Node, Deno and React Native. It keeps pdf-lib's API and docs (create, fill, read and flatten AcroForm fields, copy and merge pages, embed fonts and images) and adds what upstream lacks: opening and encrypting password-protected PDFs (AES-256 by default), incremental saves, full SVG drawing, extracting page contents, PDF/A and Factur-X/ZUGFeRD structure, attachments, PDF layers, and helpers that preserve and edit static XFA forms. Its `flatten()` also flattens orphaned widget annotations that aren't listed in the form's fields. Cantoo says it maintains the fork for its own product's needs and relies on contributions for issues outside that roadmap.

## Links

- GitHub: https://github.com/cantoo-scribe/pdf-lib

## Problems it solves

- pdf-lib hasn't had a release since 2021 and the bug I hit was fixed in a pull request nobody merged
- open a password-protected PDF in Node, change it and save it again
- encrypt a generated PDF with a password and permissions from JavaScript
- append changes to a PDF as an incremental update so earlier signatures stay intact
- draw a whole SVG file onto a PDF page from JavaScript, not just a single path
- after flattening a form, some widgets are still editable because they aren't in the AcroForm fields list
- loading and saving an XFA government form in JavaScript throws away its XFA data
- read or change the JavaScript inside an XFA form
- create a PDF/A-3 file in the browser or Node
- embed a Factur-X or ZUGFeRD XML invoice into a PDF from TypeScript
- pull the images and text out of a PDF page's content stream in JavaScript
- show or hide PDF layers (optional content groups) from code
- a truncated PDF makes my JavaScript PDF library throw instead of opening what's there
- attach files to a PDF and extract or remove existing attachments in JavaScript
- embed one face from a .ttc font collection into a PDF
- add letter spacing to text drawn on a PDF page

## Features

- pdf-lib's API and docs: create and modify PDFs, add, remove, copy and merge pages
- create, fill, read and flatten AcroForm fields; flatten() also flattens orphaned widget annotations
- open encrypted PDFs with a password; encrypt() with AES-256 (default), AES-128 or RC4
- incremental updates: append changes without rewriting the file
- full SVG drawing (drawSvg, embedSvg) as well as SVG paths
- PDFPage.extractContents(): text, images and approximate vector graphics from content streams
- XFA helpers: preserveXFA, read and modify XFA JavaScript, signature-field discovery
- document-level JavaScript extraction
- convertToPDFA() for PDF/A-1, 2 and 3 structure; embedFacturX() for Factur-X / ZUGFeRD invoices
- add, extract and detach attachments
- optional content (PDF layers) visibility
- recovers truncated PDFs and parses more malformed files
- @cantoo/fontkit support and postscriptName to pick a face from .ttc / .dfont collections
- characterSpacing on drawText
- pure JavaScript: runs in Node, browsers, Deno and React Native

## Limitations

- Doesn't extract plain text from a page outside form fields: it reads the values of text fields only[^1]
- Doesn't add HTML or CSS content to a PDF: its README points to Puppeteer for that[^1]
- Doesn't handle dynamic XFA forms: its XFA helpers target static government and tax XFA layouts[^1]
- Doesn't make files fully PDF/A compliant: convertToPDFA() adds the structure but doesn't rewrite fonts, transparency or JavaScript[^1]

## Trust

Overall: 0.27 out of 1.
Signals: backing 0.30, extensibility 0.00.

- backed by Cantoo

Warnings:

- GitHub activity not fetched yet

## Alternatives

- [PDFKit](https://talira.ai/catalog/pdfkit-2tzqj5bd.md): A JavaScript PDF generation library for Node and the browser.
- [@pdfme/pdf-lib](https://talira.ai/catalog/pdfme-pdf-lib-zn1g1rkg.md): This version is forked from Hopding/pdf-lib, with several bug fixes and additional features
- [pdf-lib](https://talira.ai/catalog/pdf-lib-80dtat8x.md): Create and modify PDF documents in any JavaScript environment.
- [Apryse SDK (WebViewer)](https://talira.ai/catalog/apryse-sdk-webviewer-69z3ztef.md): Document SDKs for viewing, editing and extracting data across 100+ formats
- [Nutrient (formerly PSPDFKit)](https://talira.ai/catalog/nutrient-formerly-pspdfkit-hx12xdjg.md): The document layer for agents
- [pdftk (PDFtk Server and pdftk-java)](https://talira.ai/catalog/pdftk-pdftk-server-and-pdftk-java-gzz4se9m.md): A command-line tool for working with PDFs

## Sources

[^1]: https://github.com/cantoo-scribe/pdf-lib (checked 20 Nov 2026)
[^2]: https://github.com/cantoo-scribe/pdf-lib/blob/master/LICENSE.md (checked 20 Nov 2026)
