# @peculiar/pdf-core

> Core functionality library for PDF document processing and manipulation

Latest version **2.0.1** (published 2026-11-02) · AGPL license · 0 weekly downloads

## Install

```sh
npm install @peculiar/pdf-core
pnpm add @peculiar/pdf-core
yarn add @peculiar/pdf-core
bun add @peculiar/pdf-core
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2026-11-02 |
| First published | 2025-01-07 |
| Weekly downloads | 0 |
| License | AGPL |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^20.19.0 \|\| >=22.12.0 |
| Dependencies | 4 |
| Unpacked size | 546.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 3 |
| Author | microshine |
| Maintainers | rmhrisk, microshine, yury.strozhevsky, peculiarventures, apilguk, donskov, worldthirteen |
| Keywords | pdf, pdf-library, pdf-manipulation, pdf-generation, pdf-parsing, encryption, digital-signatures, incremental-updates, xref, pdf-objects |

## Links

- npm: https://www.npmjs.com/package/@peculiar/pdf-core
- Repository: https://github.com/PeculiarVentures/pdf
- Homepage: https://github.com/PeculiarVentures/pdf/tree/main/packages/core#readme
- Issues: https://github.com/PeculiarVentures/pdf/issues
- npm.io page: https://npm.io/package/@peculiar/pdf-core

## Dependencies (4)

- [pako](https://npm.io/package/pako.md) ^2.2.0
- [events](https://npm.io/package/events.md) ^3.3.0
- [@types/events](https://npm.io/package/@types/events.md) ^3.0.0
- [@peculiar/utils](https://npm.io/package/@peculiar/utils.md) ^4.1.0

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2026-11-02
- 2.0.0 — 2026-11-02
- 1.17.1 — 2025-05-05
- 1.17.0 — 2025-01-07

## README

<h1 align="center">
  @peculiar/pdf-core
</h1>

<div align="center">

![GitHub License](https://img.shields.io/github/license/PeculiarVentures/pdf)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/PeculiarVentures/pdf/release.yml?branch=main&label=release)
[![npm version](https://img.shields.io/npm/v/@peculiar/pdf-core.svg)](https://www.npmjs.com/package/@peculiar/pdf-core)
[![npm downloads](https://img.shields.io/npm/dm/@peculiar/pdf-core.svg)](https://www.npmjs.com/package/@peculiar/pdf-core)

</div>

A powerful and flexible TypeScript library for PDF document manipulation, supporting both creation and modification of PDF files. The library provides comprehensive functionality for working with PDF objects, incremental updates, cross-reference tables, and encryption.

## Installation

```bash
npm install @peculiar/pdf-core reflect-metadata
```

## Breaking Changes In v2

v2 is ESM-only and requires Node.js `^20.19.0 || >=22.12.0` (1.x declared no `engines`). CommonJS code can still `require("@peculiar/pdf-core")` on these versions; Node.js 22.0–22.11 can't. See the [full notes](https://github.com/PeculiarVentures/pdf#breaking-changes-in-v2) for the x509 3 / pkijs 4 changes, the Reflect polyfill and the `@peculiar/utils` differences.

- **TypeScript compiling to CommonJS:** use `"module": "node20"` or `"nodenext"` (`node16` fails with TS1479). ESM and bundler setups need no changes.
- **Jest in CommonJS mode:** switch to ESM mode or Vitest, or configure an ESM-to-CommonJS transformer and make sure `transformIgnorePatterns` doesn't exclude the `@peculiar/*` packages.
- **Deep imports** (`@peculiar/pdf-core/build/...`) are blocked by `exports`; import from `@peculiar/pdf-core`.
- **Peer dependencies:** `@peculiar/x509` (`^3.1.0`) and `pkijs` (`^4.0.0`) are peers, so certificates, pkijs objects and the pkijs engine are your app's copies. npm installs peers automatically.
- **Reflect polyfill:** `@peculiar/x509` 3 no longer loads one. Import `reflect-metadata` (or another Reflect polyfill) once, before any other import.

## Usage

### Creating a New PDF Document

```typescript
import { PDFDocument } from "@peculiar/pdf-core";

// Create a new PDF document
const doc = PDFDocument.create();

// Add a new page
await doc.addPage();

// Convert to PDF buffer
const pdfBuffer = await doc.toPDF();
```

### Reading an Existing PDF

```typescript
import { PDFDocument } from "@peculiar/pdf-core";

// Read from buffer or string
const doc = await PDFDocument.fromPDF(existingPdfBuffer);

// Get the catalog
const catalog = doc.catalog;
```

### Working with Objects

```typescript
import { PDFDocument } from "@peculiar/pdf-core";

const doc = PDFDocument.create();

// Create basic objects
const numberObj = doc.createNumber(42);
const stringObj = doc.createString("Hello, PDF!");
const arrayObj = doc.createArray(doc.createNumber(1), doc.createString("item"));

// Create a dictionary
const dictObj = doc.createDictionary(["Key1", doc.createNumber(1)], ["Key2", doc.createString("value")]);

// Create stream
const streamObj = doc.createStream(new Uint8Array([1, 2, 3, 4]));

// Make objects indirect
const indirectObj = numberObj.makeIndirect();
```

### Incremental Updates

The library supports incremental updates, allowing you to modify PDF documents without rewriting the entire file. This approach preserves the original document's history and is more efficient for changes.

```typescript
const doc = await PDFDocument.fromPDF(existingPdfBuffer);

// Create new incremental update
await doc.createUpdate();

// Make modifications
const page = await doc.addPage();
// ... make other changes ...

// Save with incremental update
const updatedPdf = await doc.toPDF();
```

### XRef Support

The library handles both main XRef formats:

- Traditional XRef tables
- XRef streams (PDF 1.5+)

Both formats are automatically detected and processed when reading PDFs, and the library can write in either format.

### Encryption

The library implements a comprehensive Encryption Handler based on WebCrypto API, supporting both password protection and certificate-based (PKI) encryption methods. You can secure PDF documents with user and owner passwords, or use X.509 certificates for PKI-based encryption with granular permission controls.

## License

This project is dual-licensed under the AGPL-3.0 and a Commercial License:

### AGPL-3.0

The library is open-source and freely available under the terms of the Affero General Public License (AGPL-3.0). This ensures that modifications and usage in network-based applications (e.g., SaaS) must be shared under the same license.

You can use the library under AGPL-3.0 if:

- Your project is open-source and distributed under a compatible license
- Your use complies with the AGPL-3.0 requirements

### Commercial License

For use in proprietary, closed-source, or commercial projects where the AGPL is not suitable, a commercial license is available. This allows you to use the library without the AGPL's obligations.

---
_Source: https://npm.io/package/@peculiar/pdf-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
