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

paddleocr-js

v0.2.0

Published

PaddleOCR JavaScript wrapper - OCR, Table, Formula, Barcode recognition for browser and Node.js

Readme

PaddleOCR-JS

🚀 PaddleOCR JavaScript 封装,支持浏览器和 Node.js 的 OCR 识别

特性

  • 📝 文本识别 - 支持 80+ 语言的中英文识别
  • 📊 表格识别 - 精准识别表格结构,输出 HTML/Markdown/Excel
  • 🔢 公式识别 - 识别数学公式,输出 LaTeX/MathML
  • 📱 条码识别 - 支持 QR 码、条形码等 10+ 格式
  • 🗂️ 布局分析 - 自动识别文档布局结构
  • 高性能 - 模型缓存、Web Worker 支持
  • 🌐 跨平台 - 浏览器、小程序、Node.js

安装

# npm
npm install paddleocr-js

# yarn
yarn add paddleocr-js

# pnpm
pnpm add paddleocr-js

快速开始

浏览器环境

<script src="dist/browser/index.min.js"></script>
<script>
  const paddleOCR = new PaddleOCR({
    modelPath: '/models',
    useWasm: true,
    language: 'ch'
  });
  
  paddleOCR.init().then(() => {
    paddleOCR.recognize(imageElement).then(result => {
      console.log(result.textRecognition);
    });
  });
</script>

Node.js 环境

import { PaddleOCR } from 'paddleocr-js';
import fs from 'fs';

async function main() {
  const paddleOCR = new PaddleOCR({
    language: 'ch',
    useWasm: true
  });
  
  await paddleOCR.init();
  
  const imageBuffer = fs.readFileSync('image.jpg');
  const result = await paddleOCR.recognize(imageBuffer);
  
  console.log('识别结果:', result.textRecognition);
}

main();

ES Modules

import { PaddleOCR } from 'paddleocr-js';

async function detectText() {
  const paddleOCR = new PaddleOCR({
    modelPath: '/models',
    useWasm: true,
    language: 'ch'
  });
  
  await paddleOCR.init();
  
  const result = await paddleOCR.recognize('https://example.com/image.jpg');
  console.log(result);
}

detectText();

功能示例

文本识别

const paddleOCR = new PaddleOCR({
  language: 'ch',       // 语言: ch, en, fr, de, ja, ko...
  useWasm: true,        // 使用 WebAssembly 加速
  enableGPU: false,     // 启用 GPU 加速
  detectionModel: 'DB', // 检测模型: DB, DB++, EAST
  recognitionModel: 'CRNN' // 识别模型: CRNN, SVTR
});

await paddleOCR.init();
const result = await paddleOCR.recognize(imageSource);

// 结果结构
// {
//   textDetection: [{ box: [...], score: 0.95 }],
//   textRecognition: [{ text: '识别文本', score: 0.92 }],
//   duration: { total: 1200, detection: 800, recognition: 400 }
// }

表格识别

const paddleOCR = new PaddleOCR({
  enableTable: true,
  tableOptions: {
    format: 'html' // 输出格式: html, markdown, excel
  }
});

await paddleOCR.init();
const tableResult = await paddleOCR.recognizeTable(imageSource);

// tableResult.html     // HTML 表格
// tableResult.markdown // Markdown 表格
// tableResult.excel    // Base64 编码的 Excel

公式识别

const paddleOCR = new PaddleOCR({
  enableFormula: true,
  formulaOptions: {
    enableLatex: true,
    enableMathML: false
  }
});

const formulas = await paddleOCR.recognizeFormula(imageSource);

// formulas[0].latex  // LaTeX 格式: \frac{a}{b}
// formulas[0].tex    // 原始 TeX

条码识别

const paddleOCR = new PaddleOCR({
  enableBarcode: true
});

const barcodes = await paddleOCR.detectBarcodes(imageSource);

// barcodes[0].type   // 'qr_code', 'code_128'...
// barcodes[0].data   // 编码内容

批量处理

const images = ['img1.jpg', 'img2.jpg', 'img3.jpg'];
const batchResult = await paddleOCR.recognizeBatch(images);

// batchResult.results         // OCRResult 数组
// batchResult.totalDuration    // 总耗时
// batchResult.averageDuration // 平均耗时

布局分析

const paddleOCR = new PaddleOCR({
  enableLayout: true
});

const layout = await paddleOCR.analyzeLayout(imageSource);

// layout.regions[0].type  // 'text', 'title', 'figure', 'table'...
// layout.regions[0].box   // 区域坐标
// layout.regions[0].content // 区域内容

配置选项

| 选项 | 类型 | 默认值 | 说明 | |------|------|--------|------| | modelPath | string | /models | 模型路径 | | useWasm | boolean | true | 使用 WebAssembly | | useTensorflow | boolean | true | 使用 TensorFlow.js | | useONNX | boolean | false | 使用 ONNX Runtime | | language | string | ch | 识别语言 | | enableTable | boolean | false | 启用表格识别 | | enableFormula | boolean | false | 启用公式识别 | | enableBarcode | boolean | false | 启用条码识别 | | enableLayout | boolean | false | 启用布局分析 | | enableCache | boolean | true | 启用缓存 | | maxSideLen | number | 960 | 最大边长 | | threshold | number | 0.3 | 检测阈值 | | batchSize | number | 1 | 批处理大小 | | numThreads | number | 4 | WASM 线程数 |

API

PaddleOCR

主类,提供 OCR 识别功能。

class PaddleOCR {
  constructor(options?: PaddleOCROptions)
  init(): Promise<void>
  recognize(image: ImageSource, options?: ProcessOptions): Promise<OCRResult>
  recognizeBatch(images: ImageSource[], options?: ProcessOptions): Promise<BatchOCRResult>
  recognizeTable(image: ImageSource, options?: ProcessOptions): Promise<TableResult>
  analyzeLayout(image: ImageSource, options?: ProcessOptions): Promise<LayoutResult>
  recognizeFormula(image: ImageSource, options?: ProcessOptions): Promise<FormulaResult[]>
  detectBarcodes(image: ImageSource): Promise<BarcodeResult[]>
  getStats(): OCRStats
  dispose(): Promise<void>
}

静态方法

PaddleOCR.getSupportedLanguages(): string[]
PaddleOCR.getModelInfo(): ModelInfo
PaddleOCR.isSupported(): Promise<boolean>

支持的语言

  • 中文 (ch)
  • 英语 (en)
  • 法语 (fr)
  • 德语 (de)
  • 西班牙语 (es)
  • 葡萄牙语 (pt)
  • 意大利语 (it)
  • 俄语 (ru)
  • 日语 (ja)
  • 韩语 (ko)
  • 阿拉伯语 (ar)
  • 印地语 (hi)

浏览器支持

  • Chrome >= 80
  • Firefox >= 80
  • Safari >= 15
  • Edge >= 80

性能

| 场景 | 耗时 (1080p) | |------|-------------| | 文本检测 | ~300ms | | 文本识别 | ~500ms | | 表格识别 | ~1500ms | | 公式识别 | ~1000ms |

项目结构

paddle-ocr.js/
├── src/
│   ├── paddleocr.ts      # 主类
│   ├── index.ts           # 入口
│   ├── typings.ts         # 类型定义
│   ├── modules/           # 核心模块
│   │   ├── textDetector.ts
│   │   ├── textRecognizer.ts
│   │   ├── tableRecognizer.ts
│   │   ├── layoutAnalyzer.ts
│   │   ├── formulaRecognizer.ts
│   │   └── barcodeRecognizer.ts
│   └── utils/             # 工具函数
│       ├── image.ts
│       ├── cache.ts
│       └── env.ts
├── dist/                  # 编译输出
├── examples/             # 示例
└── docs/                 # 文档

License

Apache-2.0 License

贡献

欢迎提交 Issue 和 Pull Request!

相关链接