# Document OCR to JSON: images and PDFs to text, tables (`hamsmoothie/document-ocr-to-json`) Actor

Turn image and PDF URLs into clean text, key-value pairs and table rows as JSON, one row per page.

- **URL**: https://apify.com/hamsmoothie/document-ocr-to-json.md
- **Developed by:** [Maybe Quark](https://apify.com/hamsmoothie) (community)
- **Categories:** Other, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$2.00 / 1,000 one page or image of extracted texts

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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

## 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 PDF to JSON

Turn scanned PDFs and images into structured JSON. Give the actor a list of document or image URLs and it returns the extracted text, detected tables and key-value pairs, one row per page, with the source `url` on every row. It runs Tesseract OCR inside the actor, so it needs no API keys and no external services.

### Who it is for

- AI agents and LLM pipelines that need text from a scanned file before reasoning over it.
- Developers who want a cheap, pay-per-page OCR step without running their own servers.
- Operations teams digitising invoices, forms, receipts and letters.

### What each row contains

Each dataset row is one page. It has the source `url`, the page number, the extracted text, and any tables and key-value pairs found. The output is flat and ready for a spreadsheet, a database or a prompt. Open the Output tab after a run to see the exact columns.

### Three use cases

1. **Invoice and receipt intake:** extract vendor, date and totals from scans, then send them to accounting.
2. **Agent document reading:** an AI agent calls the actor through MCP to read a scanned PDF it cannot parse otherwise.
3. **Archive digitisation:** batch old scanned letters and forms into searchable JSON.

### How to use

1. Open the actor and paste one or more PDF or image URLs into the input.
2. Click Start. The default input runs a small sample.
3. Download the results from the dataset as JSON, CSV or Excel.

#### API (curl)

curl -X POST "https://api.apify.com/v2/acts/hamsmoothie~document-ocr-to-json/run-sync-get-dataset-items?token=YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{}'

An empty body uses the default input. Add your own URLs using the field names shown in the Input tab.

#### MCP (AI agents)

The actor is callable from Apify's MCP server. Search for "ocr pdf to json" and call `hamsmoothie/document-ocr-to-json` with your document URLs.

### Pricing

Pay per result: $2.00 per 1,000 pages ($0.002 per page). You only pay for rows returned.

### FAQ

**Which formats work?** Common image formats and PDFs reachable by a public URL.

**Is my data stored?** Results live in your own Apify dataset. The actor only fetches the URLs you supply.

**How accurate is it?** Tesseract works well on clean printed text. Handwriting and very low-quality scans give weaker results.

**Can it read password-protected files?** No. Only public, unprotected URLs.

### Related compliance tools

Other actors from Maybe Quark: Contractor License Verifier, FMCSA Carrier Safety Lookup, Secretary of State Business Entity Search, Healthcare Professional License Verifier, NPI Registry Lookup, Exclusion & Debarment Screener, FDA Recalls, DOL Wage & Hour Violations.

# Actor input Schema

## `documentUrls` (type: `array`):

Public URLs of images (PNG, JPG, BMP, GIF, WebP) or PDFs with a text layer.

## `language` (type: `string`):

Tesseract language code for images, for example eng, deu, fra, spa.

## `maxPagesPerPdf` (type: `integer`):

Upper bound on pages read from each PDF.

## Actor input object example

```json
{
  "documentUrls": [
    "https://tesseract.projectnaptha.com/img/eng_bw.png"
  ],
  "language": "eng",
  "maxPagesPerPdf": 20
}
```

# Actor output Schema

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

No description

# 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 = {
    "documentUrls": [
        "https://tesseract.projectnaptha.com/img/eng_bw.png"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("hamsmoothie/document-ocr-to-json").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 = { "documentUrls": ["https://tesseract.projectnaptha.com/img/eng_bw.png"] }

# Run the Actor and wait for it to finish
run = client.actor("hamsmoothie/document-ocr-to-json").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 '{
  "documentUrls": [
    "https://tesseract.projectnaptha.com/img/eng_bw.png"
  ]
}' |
apify call hamsmoothie/document-ocr-to-json --silent --output-dataset

```

## MCP server setup

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

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/VXRP1cnjDPWKCiNQU/builds/fckTntkCeCxBDQaUw/openapi.json
