LibPDF-js/core

A modern PDF library for TypeScript. Parse, modify, and generate PDFs with a clean, intuitive API.

TypeScript

1,841

269 commits

updated Oct 7, 2026

See the code

README

LibPDF

npm npm downloads CI GitHub stars License: MIT TypeScript

A modern PDF library for TypeScript. Parse, modify, and generate PDFs with a clean, intuitive API.

Beta Software: LibPDF is under active development and APIs may change between minor versions, but we use it in production at Documenso and consider it ready for real-world use.

Why LibPDF?

LibPDF was born from frustration. At Documenso, we found ourselves wrestling with the JavaScript PDF ecosystem:

  • PDF.js is excellent for rendering and even has annotation editing — but it requires a browser
  • pdf-lib has a great API, but chokes on slightly malformed documents
  • pdfkit only generates, no parsing at all

We kept adding workarounds. A patch here for a malformed xref table. A hack there for an encrypted document. Eventually, we decided to build what we actually needed:

  • Lenient like PDFBox and PDF.js: opens documents other libraries reject
  • Intuitive like pdf-lib: clean, TypeScript-first API
  • Complete: encryption, digital signatures, incremental saves, form filling

Features

FeatureStatusNotes
Parse any PDFYesGraceful fallback for malformed documents
Create PDFsYesFrom scratch or modify existing
EncryptionYesRC4, AES-128, AES-256 (R2-R6)
Digital SignaturesYesPAdES B-B, B-T, B-LT, B-LTA
Form FillingYesText, checkbox, radio, dropdown, signature
Form FlatteningYesBake fields into page content
Merge & SplitYesCombine or extract pages
AttachmentsYesEmbed and extract files
Text ExtractionYesWith position information
Font EmbeddingYesTTF/OpenType with subsetting
ImagesYesJPEG, PNG (with alpha)
Incremental SavesYesAppend changes, preserve signatures

Installation

npm install @libpdf/core
# or
bun add @libpdf/core

Quick Start

Parse an existing PDF

import { PDF } from "@libpdf/core";

const pdf = await PDF.load(bytes);
const pages = pdf.getPages();

console.log(`${pages.length} pages`);

Open an encrypted PDF

const pdf = await PDF.load(bytes, { credentials: "password" });

Fill a form

const pdf = await PDF.load(bytes);
const form = pdf.getForm();

form.fill({
  name: "Jane Doe",
  email: "jane@example.com",
  agreed: true,
});

const filled = await pdf.save();

Sign a document

import { PDF, P12Signer } from "@libpdf/core";

const pdf = await PDF.load(bytes);
const signer = await P12Signer.create(p12Bytes, "password");

const signed = await pdf.sign({
  signer,
  reason: "I approve this document",
});

Merge PDFs

const merged = await PDF.merge([pdf1Bytes, pdf2Bytes, pdf3Bytes]);

Draw on a page

import { PDF, rgb } from "@libpdf/core";

const pdf = PDF.create();
const page = pdf.addPage({ size: "letter" });

page.drawText("Hello, World!", {
  x: 50,
  y: 700,
  fontSize: 24,
  color: rgb(0, 0, 0),
});

page.drawRectangle({
  x: 50,
  y: 600,
  width: 200,
  height: 100,
  color: rgb(0.9, 0.9, 0.9),
  borderColor: rgb(0, 0, 0),
  borderWidth: 1,
});

const output = await pdf.save();

Runtime Support

LibPDF runs everywhere:

  • Node.js 20+
  • Bun
  • Browsers (modern, with Web Crypto)

Known Limitations

Some features are not yet implemented:

FeatureStatusNotes
Signature verificationNot implementedSigning works; verification is planned
TrueType Collections (.ttc)Not supportedExtract individual fonts first
JBIG2 image decodingPassthrough onlyImages preserved but not decoded
JPEG2000 (JPX) decodingPassthrough onlyImages preserved but not decoded
Certificate encryptionNot supportedPassword encryption works
JavaScript actionsIgnoredForm calculations not executed

These limitations are documented to set expectations. Most don't affect typical use cases like form filling, signing, or document manipulation.

Philosophy

Be lenient

Real-world PDFs are messy. Export a document through three different tools and you'll get three slightly different interpretations of the spec. LibPDF prioritizes opening your document over strict compliance. When standard parsing fails, we fall back to brute-force recovery, scanning the entire file to rebuild the structure.

Two API layers

  • High-level: PDF, PDFPage, PDFForm for common tasks
  • Low-level: PdfDict, PdfArray, PdfStream for full control

Documentation

Full documentation at libpdf.dev

Sponsors

LibPDF is developed by Documenso, the open-source DocuSign alternative.

Documenso

Contributing

We welcome contributions! See our contributing guide for details.

# Clone the repo
git clone https://github.com/LibPDF-js/core.git libpdf
cd libpdf

# Install dependencies
bun install

# Run tests
bun run test

# Type check
bun run typecheck

License

MIT

The src/fontbox/ directory is licensed under Apache-2.0 as it is derived from Apache PDFBox.

digital-signature
document
esign
generator
pades
parser
pdf
pdf-document
pdf-generator
pdf-parsing
pkcs7
signing
typescript

LibPDF-js/core

A modern PDF library for TypeScript. Parse, modify, and generate PDFs with a clean, intuitive API.

TypeScript

1,841

269 commits

updated Oct 7, 2026

See the code

README

LibPDF

npm npm downloads CI GitHub stars License: MIT TypeScript

A modern PDF library for TypeScript. Parse, modify, and generate PDFs with a clean, intuitive API.

Beta Software: LibPDF is under active development and APIs may change between minor versions, but we use it in production at Documenso and consider it ready for real-world use.

Why LibPDF?

LibPDF was born from frustration. At Documenso, we found ourselves wrestling with the JavaScript PDF ecosystem:

  • PDF.js is excellent for rendering and even has annotation editing — but it requires a browser
  • pdf-lib has a great API, but chokes on slightly malformed documents
  • pdfkit only generates, no parsing at all

We kept adding workarounds. A patch here for a malformed xref table. A hack there for an encrypted document. Eventually, we decided to build what we actually needed:

  • Lenient like PDFBox and PDF.js: opens documents other libraries reject
  • Intuitive like pdf-lib: clean, TypeScript-first API
  • Complete: encryption, digital signatures, incremental saves, form filling

Features

FeatureStatusNotes
Parse any PDFYesGraceful fallback for malformed documents
Create PDFsYesFrom scratch or modify existing
EncryptionYesRC4, AES-128, AES-256 (R2-R6)
Digital SignaturesYesPAdES B-B, B-T, B-LT, B-LTA
Form FillingYesText, checkbox, radio, dropdown, signature
Form FlatteningYesBake fields into page content
Merge & SplitYesCombine or extract pages
AttachmentsYesEmbed and extract files
Text ExtractionYesWith position information
Font EmbeddingYesTTF/OpenType with subsetting
ImagesYesJPEG, PNG (with alpha)
Incremental SavesYesAppend changes, preserve signatures

Installation

npm install @libpdf/core
# or
bun add @libpdf/core

Quick Start

Parse an existing PDF

import { PDF } from "@libpdf/core";

const pdf = await PDF.load(bytes);
const pages = pdf.getPages();

console.log(`${pages.length} pages`);

Open an encrypted PDF

const pdf = await PDF.load(bytes, { credentials: "password" });

Fill a form

const pdf = await PDF.load(bytes);
const form = pdf.getForm();

form.fill({
  name: "Jane Doe",
  email: "jane@example.com",
  agreed: true,
});

const filled = await pdf.save();

Sign a document

import { PDF, P12Signer } from "@libpdf/core";

const pdf = await PDF.load(bytes);
const signer = await P12Signer.create(p12Bytes, "password");

const signed = await pdf.sign({
  signer,
  reason: "I approve this document",
});

Merge PDFs

const merged = await PDF.merge([pdf1Bytes, pdf2Bytes, pdf3Bytes]);

Draw on a page

import { PDF, rgb } from "@libpdf/core";

const pdf = PDF.create();
const page = pdf.addPage({ size: "letter" });

page.drawText("Hello, World!", {
  x: 50,
  y: 700,
  fontSize: 24,
  color: rgb(0, 0, 0),
});

page.drawRectangle({
  x: 50,
  y: 600,
  width: 200,
  height: 100,
  color: rgb(0.9, 0.9, 0.9),
  borderColor: rgb(0, 0, 0),
  borderWidth: 1,
});

const output = await pdf.save();

Runtime Support

LibPDF runs everywhere:

  • Node.js 20+
  • Bun
  • Browsers (modern, with Web Crypto)

Known Limitations

Some features are not yet implemented:

FeatureStatusNotes
Signature verificationNot implementedSigning works; verification is planned
TrueType Collections (.ttc)Not supportedExtract individual fonts first
JBIG2 image decodingPassthrough onlyImages preserved but not decoded
JPEG2000 (JPX) decodingPassthrough onlyImages preserved but not decoded
Certificate encryptionNot supportedPassword encryption works
JavaScript actionsIgnoredForm calculations not executed

These limitations are documented to set expectations. Most don't affect typical use cases like form filling, signing, or document manipulation.

Philosophy

Be lenient

Real-world PDFs are messy. Export a document through three different tools and you'll get three slightly different interpretations of the spec. LibPDF prioritizes opening your document over strict compliance. When standard parsing fails, we fall back to brute-force recovery, scanning the entire file to rebuild the structure.

Two API layers

  • High-level: PDF, PDFPage, PDFForm for common tasks
  • Low-level: PdfDict, PdfArray, PdfStream for full control

Documentation

Full documentation at libpdf.dev

Sponsors

LibPDF is developed by Documenso, the open-source DocuSign alternative.

Documenso

Contributing

We welcome contributions! See our contributing guide for details.

# Clone the repo
git clone https://github.com/LibPDF-js/core.git libpdf
cd libpdf

# Install dependencies
bun install

# Run tests
bun run test

# Type check
bun run typecheck

License

MIT

The src/fontbox/ directory is licensed under Apache-2.0 as it is derived from Apache PDFBox.

digital-signature
document
esign
generator
pades
parser
pdf
pdf-document
pdf-generator
pdf-parsing
pkcs7
signing
typescript

Project health

Latest release

0.5.2 · Oct 7, 2026

Releases this year

27

Significant stargazers

(top 24 of 42)

Michaël De Boey

991 followers · starred Jan 2026

Tim Perry

789 followers · starred Jan 2026

Kirill Fomichev

490 followers · starred Jul 2026

leah

443 followers · starred Jun 2026