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

@kafkaliu/nezha-ocr-cli

v0.1.2

Published

CLI tool to convert PDF to JSON-AST using PaddleOCR API

Readme

nezha-ocr-cli

中文版

A CLI tool to convert PDF documents to JSON-AST format using PaddleOCR API.

Features

  • 📄 PDF Processing: Support for multi-page PDF document OCR recognition
  • 🔄 Split and Merge: Automatic splitting for large files, with automatic result merging
  • 📊 Structured Output: Returns structured data including text, layout, tables, and more
  • 🎯 High Accuracy: Support for document orientation classification, table recognition, and other advanced features

Installation

npm install -g @kafkaliu/nezha-ocr-cli

After installation, use the nezha-ocr command to run.

Or use npx directly (no installation required):

npx @kafkaliu/nezha-ocr-cli input.pdf

Usage

Basic Usage

nezha-ocr input.pdf

Output to File

nezha-ocr input.pdf -o output.json

Using Environment Variables

OCR_API_URL="https://your-api-url.com" \
OCR_API_TOKEN="your-token" \
nezha-ocr input.pdf -o output.json

Command Line Options

| Option | Short | Description | Default | |--------|-------|-------------|----------| | --api-url <url> | -u | PaddleOCR API URL | OCR_API_URL env var | | --token <token> | -t | PaddleOCR API token | OCR_API_TOKEN env var | | --output <file> | -o | Output file name | stdout | | --format <format> | -f | Output format | json | | --max-pages <number> | -m | Maximum pages per API call | 100 | | --file-type <type> | | File type (0=PDF, 1=images) | 0 | | --use-doc-orientation-classify | | Use document orientation classification | false | | --use-doc-unwarping | | Use document unwarping | false | | --use-chart-recognition | | Use chart recognition | false |

Output Format

The OCR API returns data in the following structure:

{
  logId: string;
  errorCode: number;
  errorMsg: string;
  result: {
    layoutParsingResults: [
      {
        prunedResult: {
          page_count: number;
          width: number;
          height: number;
          model_settings: ModelSettings;
          parsing_res_list: [
            {
              block_label: string;      // Block type (text, title, table, etc.)
              block_content: string;     // OCR recognized text
              block_bbox: number[];      // Bounding box [x1, y1, x2, y2]
              block_id: number;
              block_order: number;
              group_id: number;
              block_polygon_points: number[][];  // Polygon coordinates
            }
          ];
        };
        markdown: {
          text: string;
          images: Record<string, string>;
        };
      }
    ];
    dataInfo: {
      type: 'pdf' | 'image';
      numPages: number;
      pages: Array<{ width: number; height: number }>;
    };
  };
}

Development

Install Dependencies

npm install

Build

npm run build

Run Tests

# Run all tests (unit tests only, no API required)
npm test

# Run only unit tests
npm run test:unit

# Run integration tests (requires OCR environment variables)
npm run test:integration

# Watch mode
npm run test:watch

# Generate coverage report
npm run test:coverage

Test Environment Variables

Integration tests require the following environment variables:

export OCR_API_URL="https://your-api-url.com/layout-parsing"
export OCR_API_TOKEN="your-api-token"

If these are not set, integration tests will be skipped.

Generate Test PDF

npm run test:fixtures

This generates a test PDF file in the test-data/ directory.

Publishing

# Update version and create tag (automatically updates package.json)
npm version patch   # 0.1.0 → 0.1.1 (bug fixes)
npm version minor   # 0.1.0 → 0.2.0 (new features)
npm version major   # 0.1.0 → 1.0.0 (breaking changes)

# Push code and tag
git push
git push origin v0.1.1

After pushing the tag, GitHub Actions will automatically run tests, build, and publish to npm.

Project Structure

nezha-ocr-cli/
├── src/                    # Source code
│   ├── cli.ts             # CLI entry point
│   ├── ocr-client.ts      # OCR API client
│   ├── pdf-splitter.ts    # PDF splitting
│   ├── result-merger.ts   # Result merging
│   └── types.ts           # Type definitions
├── tests/                  # Test code
│   ├── unit/              # Unit tests
│   ├── integration/       # Integration tests
│   ├── fixtures/          # Test utilities
│   └── setup.ts           # Test configuration
├── test-data/             # Test data
├── dist/                  # Build output
└── package.json

License

MIT