npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@peculiar/pdf-core

v2.0.1

Published

Core functionality library for PDF document processing and manipulation

Readme

GitHub License GitHub Actions Workflow Status npm version npm downloads

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

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 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

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

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

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.

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.