# Image & Document OCR — Chinese-First Text Extraction (`variable_paddock/ocr-to-text`) Actor

OCR images and scanned PDFs into plain text or Markdown. Strong on Simplified/Traditional Chinese and mixed CN/EN pages. One dataset item per page with warnings for low-confidence blocks.

- **URL**: https://apify.com/variable_paddock/ocr-to-text.md
- **Developed by:** [Tang](https://apify.com/variable_paddock) (community)
- **Categories:** AI, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## OCR to Text — images to text (Chinese first)

OCR images (screenshots, scans, invoices, receipts) into structured text using **PaddleOCR PP-OCRv4 + ONNX** (`@gutenye/ocr-node`). **No API keys, no external OCR service** — the model runs inside the Actor container.

### Output (one dataset record per image)

```json
{
  "source": "https://example.com/scan.png",
  "text": "发票号码 12345678\n开票日期 2026年11月10日 ...",
  "lines": [
    { "text": "发票号码 12345678", "confidence": 0.98, "box": [[10,20],[300,20],[300,48],[10,48]] }
  ],
  "lang": "ch",
  "elapsedMs": 1840
}
```

- `outputMode: "markdown"` adds a `markdown` field (heading + plain text) for direct reading.
- Failed images push `{ source, error }` and the run continues with the next image.
- No `lines` detections (blank image) still returns a record with `text: ""`.

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `imageUrls` | array of strings | — | Public http(s) image URLs |
| `imagesBase64` | array of strings | — | Raw base64 or `data:image/...;base64,...` (max 15 MB each) |
| `lang` | string | `ch` | OCR language (`ch` first; `en` etc. if supported by the model) |
| `outputMode` | `text` / `markdown` | `text` | Add Markdown rendering or not |

#### Example

```json
{
  "imageUrls": ["https://example.com/scan.png"],
  "lang": "ch",
  "outputMode": "text"
}
```

### Limitations

- **Printed text first** — Chinese/English printed screenshots and scans work best.
- **Handwriting is poor** — handwritten invoices/notes are not reliable; expect low confidence or misses.
- **Chinese-first** — default model targets Chinese; other languages depend on the package's available models.
- Rotated/skewed photos and very low-resolution images degrade accuracy; pre-crop if possible.
- Models are heavy (~300 MB) — the first cloud build may take **6–10 minutes** and cold start downloads/loads models.
- No PDF input (convert PDF pages to images first).

### Build / deploy notes

- `.actor/actor.json`: `actorSpecification: 1`, `version: "0.0"`, input/readme copied inside `.actor/`.
- Dockerfile: `node:22-slim` + `libgomp1` (onnxruntime requirement) + `npm ci --omit=dev` + `CMD node src/main.js`.
- Dependencies are installed **in the cloud build**, not on the local machine.
- When creating the Actor, pass **source file contents as plain text**, not base64.
- No local `npm install` was performed for verification; only static checks (`node --check`, JSON schema validity) locally. Real verification happens on the Apify build+run.

# Actor input Schema

## `imageUrls` (type: `array`):

One or more public http(s) image URLs (jpg/png/webp).

## `imagesBase64` (type: `array`):

Alternative to imageUrls: array of raw base64 or data:image/...;base64,... strings (max 15MB each).

## `lang` (type: `string`):

Language model: ch (Chinese, default), en, or package-supported codes.

## `outputMode` (type: `string`):

text = plain text items; markdown = adds a Markdown rendering field.

## Actor input object example

```json
{
  "lang": "ch",
  "outputMode": "text"
}
```

# Actor output Schema

## `results` (type: `string`):

Each item: source, lang, text, lines\[], chars, mode (and markdown when requested).

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("variable_paddock/ocr-to-text").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("variable_paddock/ocr-to-text").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call variable_paddock/ocr-to-text --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,variable_paddock/ocr-to-text"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/kIGflBcym7KCQ0Ngs/builds/rhFtjYNoeNbXZ5B97/openapi.json
