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

@pdfextract/ocr

v0.3.0

Published

Lazy, self-hosted Tesseract OCR provider for @pdfextract/core in browsers and Node.js. No CDN or implicit model downloads.

Readme

@pdfextract/ocr

Lazy Tesseract.js 7 provider for @pdfextract/core, browser and Node ≥22.12.0. Tesseract recognizes rasters; core parses the PDF and supplies their page transforms.

Installation

pnpm add @pdfextract/core @pdfextract/ocr

Supply Tesseract-compatible language models separately.

Usage

For this Node example, put eng.traineddata.gz in a models/ directory next to the script. Package runtime assets are resolved automatically in Node:

import { readFile } from 'node:fs/promises';
import { openPdf } from '@pdfextract/core';
import { createTesseractOcr } from '@pdfextract/ocr';

const ocr = createTesseractOcr({
  languages: ['eng'],
  concurrency: 1,
  assets: { languageDataBaseUrl: new URL('./models/', import.meta.url) },
});
try {
  const pdf = await openPdf(await readFile('input.pdf'), { ocr });
  try {
    const text = await pdf.getStructuredText({ ocr: 'auto' });
    console.log(text.fullText);
  } finally {
    await pdf.close();
  }
} finally {
  await ocr.close();
}

Add 'deu' and supply deu.traineddata.gz for German recognition. In browsers, pass a whole File to core and configure all worker/model URLs using the self-hosted asset guide.

Lifecycle

The factory is synchronous and performs no initialization/download. First recognition loads a reusable worker. Concurrency defaults to 1, configurable 1–8. The caller owns the provider: multiple PDFs may share it, and closing one PDF does not terminate it. close() is idempotent; cancellation terminates a running or initializing worker. Missing models reject with OCR_ASSET_UNAVAILABLE, not a pending initialization promise.

Self-hosted assets

Language paths are required at recognition time to prevent an implicit external CDN. Use Tesseract-compatible eng.traineddata.gz, deu.traineddata.gz, etc. Model files are deliberately separate from the tarball. For browsers, copy all dist/assets files and set workerUrl to the copied worker.min.js, coreBaseUrl to its core/ directory, and languageDataBaseUrl to your models directory. The patched tesseract.mjs controller is loaded beside worker.min.js. The same configuration works from a window or a dedicated Web Worker. Node resolves the package's node export condition and uses the bundled Node controller/worker and the packaged Tesseract core, so no tesseract.js dependency is installed. Node model, worker and core-directory paths may be absolute paths or file URLs. Only the LSTM cores are shipped (baseline, SIMD and relaxed-SIMD); the matching variant is chosen at runtime. No shared-memory/ cross-origin-isolation headers are required.

Recognition and errors

The provider accepts tightly packed RGBA8, returns pixel-coordinate words/lines and confidence in [0,1]. It uses no automatic rotation/resizing; core maps recognition geometry through its own preprocessing. auto in core visits image regions even on pages containing native text. always uses a bounded full-page working raster. Native text wins overlapping normalized matching words; distinct placements remain. Automatic detection of arbitrary page layouts/languages or guaranteed OCR accuracy is not claimed. Test thresholds require the known English/German sentinel words and geometry.

Runtime errors include INVALID_ARGUMENT, OCR_ASSET_UNAVAILABLE, OCR_FAILED, ABORTED, and DOCUMENT_CLOSED. Progress reports OCR stages. Engine types are private; the public provider contract belongs to core. This package does not own PDF handles or storage.

License

MIT. Tesseract, Leptonica, bundled codecs and math licenses are included in THIRD_PARTY_NOTICES; model licenses must be hosted with separately supplied models.