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

@ocr-web/pdf

v0.3.0

Published

PDF text extraction via @ocr-web/core (renders pages with pdfjs-dist, OCRs each page)

Readme

@ocr-web/pdf

PDF 文本提取,基于 @ocr-web/core。把每一页用 pdfjs-dist 渲染成图片后喂给 OcrEngine。

安装

pnpm add @ocr-web/pdf @ocr-web/core @ocr-web/models-ppocrv5 onnxruntime-web

用法

import { OcrEngineWorker } from "@ocr-web/core";
import OcrWorker from "@ocr-web/core/worker?worker";
import { ppocrV5 } from "@ocr-web/models-ppocrv5";
import { PdfOcr } from "@ocr-web/pdf";

const engine = await OcrEngineWorker.create({
  worker: new OcrWorker(),
  models: { detection: ppocrV5.detection, recognition: ppocrV5.recognition },
  dictionary: ppocrV5.dictionary,
  wasmPaths: "/ort/",
});

const pdfOcr = new PdfOcr({ engine });

// 单页 → 直接返回字符串
const text = await pdfOcr.recognize(file, 3);

// 全部页 → 返回 { 页号: { text, lines, durationMs } }
const all = await pdfOcr.recognize(file);
console.log(all[1].text, all[2].text);

// 指定多页
const some = await pdfOcr.recognize(file, [1, 3, 5]);

API

type PdfInput = ArrayBuffer | Uint8Array | Blob | string;

class PdfOcr {
  constructor(opts: PdfOcrOptions);
  recognize(pdf: PdfInput, page: number): Promise<string>;
  recognize(pdf: PdfInput, pages?: "all" | number[]): Promise<PdfRecognizeResult>;
  pageCount(pdf: PdfInput): Promise<number>;
}

interface PdfOcrOptions {
  engine: OcrEngine | OcrEngineWorker;
  scale?: number;          // pdfjs render scale, default 2 (2x dpi, 利于小字 OCR)
  workerSrc?: string;      // pdfjs worker URL,默认走 jsDelivr CDN
  recognize?: RecognizeOptions;  // 透传给 engine.recognize
  onPageProgress?: (current: number, total: number, page: number) => void;
}

interface PdfPageRecognizeResult {
  text: string;
  lines: OcrLine[];
  durationMs: number;
}

type PdfRecognizeResult = Record<number, PdfPageRecognizeResult>;

注意

  • pdfjs worker:默认从 jsDelivr CDN 加载 pdf.worker.min.mjs(带 CORS)。如果你的应用需要离线/CSP 严格,传 workerSrc 指向自己 host 的副本。
  • render scale:默认 2x。文档清晰度低或字号小可以提高到 3-4,代价是耗时和内存增加。
  • 页号 1-indexed:跟 PDF 习惯一致,跟 pdfjs 一致。

License

MIT