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

clawpdf

v0.3.0

Published

Zero-dependency PDFium WASM bindings for PDF text extraction and page rendering.

Readme

clawpdf

clawpdf banner

CI

Zero-dependency PDFium WebAssembly bindings for Node and browsers.

Docs: https://clawpdf.dev/

clawpdf loads PDFs, extracts text, renders pages, and encodes PNG fallback images without runtime dependencies, native addons, postinstall scripts, or a canvas package.

Why

OpenClaw needs a predictable local PDF path:

  • text extraction before model fallback
  • page rendering when a PDF has little extractable text
  • PNG output for multimodal model input
  • one dependency with no transitive package tree
  • current vendored PDFium provenance

This package currently vendors pdfium-lib release 7623.

Install

npm install clawpdf

ESM-only. Node 20+ is supported.

Quick Start

import { writeFile } from "node:fs/promises";
import { openPdf } from "clawpdf";

await using pdf = await openPdf("report.pdf");

console.log(pdf.pageCount);
console.log(pdf.text({ maxPages: 5 }));

const png = await pdf.page(1).png({ dpi: 144, forms: true });
await writeFile("page-1.png", png);

All user-facing page numbers are one-based.

CLI

The package also installs a clawpdf command:

clawpdf report.pdf
cat report.pdf | clawpdf -
clawpdf report.pdf --json
clawpdf render report.pdf --page 1 > page.png
clawpdf render report.pdf --page 1 --inline auto

Use --password or --password-file for encrypted PDFs. See the CLI docs for flags, JSON output, and exit codes.

Reuse an Engine

Server code should create one PDFium engine and reuse it:

import { createEngine } from "clawpdf";

await using engine = await createEngine();

await using pdf = await engine.open(pdfBytes);

console.log(pdf.metadata.title);
console.log(pdf.page(1).text());

Use engine.extract(...) when you want the same text-first fallback behavior without manually opening and closing a document:

const result = await engine.extract(pdfBytes, { mode: "auto", maxPages: 20 });

Text-First Extraction

import { extractPdf } from "clawpdf";
import { toMessageContent } from "clawpdf/adapters";

const result = await extractPdf("report.pdf", {
  mode: "auto",
  minTextChars: 200,
  maxPages: 20,
  image: {
    dpi: 96,
    maxPixels: 4_000_000,
    maxDimension: 10_000,
    forms: true,
  },
});

console.log(result.text);
console.log(result.images); // raw PNG bytes
console.log(toMessageContent(result)); // transport-shaped blocks

auto always extracts text and renders PNG images only when extracted text is shorter than minTextChars.

Browser Usage

Use clawpdf/browser in bundled browser code. It exports the same API and pre-wires the packaged WASM URL.

import { openPdf } from "clawpdf/browser";

await using pdf = await openPdf(file);
console.log(pdf.text({ maxPages: 3 }));

Custom WASM hosting is still available:

import { createEngine } from "clawpdf/browser";

await using engine = await createEngine({
  wasmUrl: "/assets/pdfium.esm.wasm",
});

Passwords

import { openPdf } from "clawpdf";

await using pdf = await openPdf("secret.pdf", { password: "secret" });
console.log(pdf.text());

Wrong or missing passwords throw PdfPasswordError.

API

Feature docs:

Core exports:

  • extractPdf(input, options?): one-shot extraction with a shared engine.
  • openPdf(input, options?): open one document with private lifetime.
  • createEngine(options?): create a reusable PDFium engine.
  • releaseExtractEngine(): dispose the shared extraction engine after in-flight calls finish.
  • encodePng(rgba, { width, height, compress }): standalone RGBA to PNG.
  • PdfError subclasses for typed failures.
  • PDFIUM_RELEASE and PDFIUM_WASM_SHA256.

Performance Snapshot

Local Node benchmark on five sample PDFs, first page rendered at scale 2 with text extraction and PNG encoding included.

| Sample | previous stack total / RSS / PNG | clawpdf total / RSS / PNG | | --- | --- | --- | | Form | 95.4 ms / 174.9 MB / 114,930 B | 38.7 ms / 129.4 MB / 100,629 B | | Hello | 65.2 ms / 159.7 MB / 41,408 B | 27.2 ms / 124.1 MB / 47,106 B | | Scientific | 176.9 ms / 202.0 MB / 608,807 B | 66.0 ms / 137.8 MB / 321,122 B | | Magazine | 519.4 ms / 312.0 MB / 1,616,318 B | 255.9 ms / 179.5 MB / 1,930,947 B | | Checkmark | 2.6 ms / 128.1 MB / 589 B | 1.1 ms / 83.2 MB / 498 B |

Package Shape

Runtime dependencies: none. Release history: see CHANGELOG.md.

Published files:

  • dist/index.js
  • dist/cli.d.ts
  • dist/cli.js
  • dist/browser.js
  • dist/adapters/index.js
  • dist/vendor/pdfium.esm.js
  • dist/vendor/pdfium.esm.wasm
  • CHANGELOG.md
  • license/readme/notices

Current vendored binary:

  • pdfium-lib: 7623
  • WASM SHA-256: 14ca2adbe23b45dea57da28ae2746e376f1cddfb8e2d0b01b71dcc5cf227734e

Refresh PDFium

pnpm download:pdfium
pnpm test

To move to a newer pdfium-lib release, update the release tag and hashes in:

  • scripts/download-pdfium.mjs
  • src/constants.ts
  • this README
  • docs/pdfium-provenance.md

License

MIT for this wrapper. PDFium has upstream BSD-style and Apache-2.0 notices; see THIRD_PARTY_NOTICES.md.