# PDF & Image OCR: scanned documents to text, Markdown and tables (`nelyon/pdf-image-ocr`) Actor

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

## Pricing

from $4.00 / 1,000 scanned page ocrs

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

## PDF & Image OCR: scanned documents to text, Markdown and tables

Turn scanned PDFs, phone photos and screenshots into clean text and Markdown, with simple tables detected. Paste file URLs; the Actor uses a PDF's own text layer where it exists (exact and cheap) and runs OCR only on pages that have none. English and Indonesian work out of the box, plus the other Latin-script languages. No API key, no browser, no login.

### What you get

One dataset row per file you submit, always, including when something went wrong (`status` tells you what happened):

| Field | Meaning |
|---|---|
| `url`, `fileType`, `sizeBytes` | the file as submitted; `pdf` or `image` (detected from the file contents) |
| `status` | `ok`, `partial`, `no_text_found`, `error`, `skipped` |
| `pageCount`, `pagesProcessed` | pages in the file / pages actually read |
| `pagesOcred`, `pagesWithTextLayer` | how each page was read |
| `text`, `markdown` | all processed pages; pages are separated by `<!-- page N -->` in Markdown |
| `tables` | `[{page, rows: [[cell, ...], ...]}]` for tables found in the page layout |
| `pages` | per page: `source`, `chars`, `confidence`, `charged`; with `perPage` also its text/Markdown |
| `confidence` | mean OCR confidence 0-1 over OCR'd pages (null if no page needed OCR) |
| `errorCode`, `error` | machine code and plain explanation when `status` is not `ok` |

`errorCode` values: `not_found`, `access_denied` (login or bot block), `unreachable`, `timeout`, `too_large`, `too_many_redirects`, `blocked_address`, `invalid_url`, `http_error`, `unsupported_content` (e.g. an HTML page), `password_protected`, `corrupt_file`, `page_errors`, `no_text_found`, `max_pages`, `spending_limit`, `free_plan_limit`, `internal_error`.

### Use cases

- **Document and RAG pipelines**: turn scanned contracts, reports and invoices into Markdown chunks (`perPage: true`) for search or LLM input.
- **Back-office automation**: pull amounts and line items out of scanned invoices and statements via `tables`.
- **Archives and digitisation**: make old scans searchable; Indonesian and other Latin-script documents are supported.
- **AI agents and MCP**: one call returns text or Markdown for any PDF or image URL, with explicit status and error codes an agent can act on.

### Input

```json
{
  "urls": [
    "https://example.com/scanned-invoice.pdf",
    "https://example.com/receipt-photo.jpg"
  ],
  "languages": ["en", "id"],
  "outputFormat": "both",
  "ocrMode": "auto",
  "quality": "accurate",
  "maxPages": 50,
  "perPage": false
}
```

- `urls` (required): direct http(s) links to PDF, PNG, JPEG, WebP or TIFF files. The type is detected from the file's bytes, not the URL or Content-Type. Max 50 MB per file.
- `languages` (default `["en"]`): `en`, `id` (Indonesian), `ms`, `es`, `fr`, `de`, `pt`, `it`, `nl`, `tr`, `vi`, `pl`, `ro`, `sv`, `da`, `fi`, `no`, `cs`, `hu`, `sk`, `sl`, `hr`, `tl`, `sw`, `ch` (Chinese), `japan`. One multilingual model reads all of them at once, so this field is validated and logged rather than switching models. Unknown codes are ignored with a warning.
- `outputFormat` (default `both`): `text`, `markdown` or `both`.
- `ocrMode` (default `auto`): `auto` = text layer where a page has one, OCR otherwise; `always` = OCR every page (for PDFs with a broken or hidden text layer).
- `quality` (default `accurate`): `accurate` = larger model, about 4-7 s per page; `fast` = small model, noticeably quicker, with more merged words and misreads on hard scans. Same price.
- `maxPages` (default **50**): first N pages of each PDF (or frames of a multi-page TIFF). A longer file comes back as `partial` with `errorCode: "max_pages"`.
- `perPage` (default `false`): add each page's text/Markdown to `pages`.

### Output example

```json
{
  "url": "https://example.com/mixed.pdf",
  "status": "ok",
  "fileType": "pdf",
  "sizeBytes": 1245693,
  "pageCount": 3,
  "pagesProcessed": 3,
  "pagesOcred": 2,
  "pagesWithTextLayer": 1,
  "text": "Quarterly Maintenance Report\n\nThis report summarizes ...",
  "markdown": "<!-- page 1 -->\n\n# Quarterly Maintenance Report\n\nThis report summarizes ...\n\n<!-- page 2 -->\n\n## Cost Summary\n\n| Item | Qty | Unit price | Total |\n|---|---|---|---|\n| Air filter | 12 | 15.50 | 186.00 |\n...",
  "tables": [{"page": 2, "rows": [["Item", "Qty", "Unit price", "Total"], ["Air filter", "12", "15.50", "186.00"]]}],
  "pages": [
    {"page": 1, "source": "text-layer", "chars": 444, "confidence": null, "charged": "page-text-layer"},
    {"page": 2, "source": "ocr", "chars": 247, "confidence": 0.997, "charged": "page-ocr"}
  ],
  "confidence": 0.9961,
  "errorCode": null,
  "error": null,
  "processedAt": "2026-11-14T08:41:07Z"
}
```

### Pricing

Pay per page, for pages that contain text:

| Event | Price | What it is |
|---|---|---|
| `page-text-layer` | **$0.002** | a PDF page whose embedded text was extracted (no OCR) |
| `page-ocr` | **$0.004** | a scanned PDF page or an image read with OCR |

Pages where no text is found are **not charged**, and neither are files that fail to download or open. Set the run's maximum cost to cap spend: the Actor stops cleanly at the limit, marks the file `partial` (or later files `skipped`) and keeps everything read so far.

**Free Apify plan:** runs are limited to the first 5 pages in total (later files come back `skipped`, the cut file `partial` with `free_plan_limit`). Paid plans have no page cap other than `maxPages`.

### Speed

Measured on one CPU thread (the share a default 4 GB Apify run gets), clean self-rendered A4 pages at 200 dpi: about 1 s per page with `fast` and 4-7 s per page with `accurate` (the range is the same machine quiet and busy). PDF pages that have a text layer take milliseconds. Memory: about 0.8 GB (`fast`) to 1.6 GB (`accurate`) peak; the Actor defaults to 4 GB.

### Limits and notes

- **Not guaranteed:** handwriting, heavy stamps and stains, very low-resolution or blurry photos. The Actor returns what the OCR model reads together with a confidence; check `confidence` (below roughly 0.85, look at the text).
- **Layout is simple.** Headings (by relative text size), paragraphs, bullet lists and tables whose columns line up are detected. Merged cells, tables without clear column gaps and multi-line cells are not. **Multi-column pages and forms** (newspapers, tax forms) are read row by row across the columns, so the text of neighbouring columns can interleave; they are not reordered into reading flow. Two prose columns are not mistaken for a table.
- Rotated pages (90 or 270 degrees) are not auto-rotated; upright text and small skew are handled. Photos are rotated by their EXIF orientation.
- Only public files reachable with a plain GET. Links that need a login, cookies or a captcha come back as `access_denied` or `unsupported_content` (HTML page). No crawling: each URL is fetched once, with up to 5 redirects, a 90 s limit and a 50 MB size limit. URLs pointing at private or internal network addresses are refused.
- PDFs with a password come back as `password_protected`. Files that are not PDF/PNG/JPEG/WebP/TIFF (including GIF and HTML) come back as `unsupported_content`.
- A PDF page counts as having a text layer when it has at least 20 characters of embedded text, or any text at all and no image on the page. A scanned PDF that already carries an OCR text layer is therefore read from that layer (use `ocrMode: "always"` to OCR it fresh).
- Tiny runs cost the same per page, but each run has fixed platform overhead; batching many files in one run is cheaper for you and for us.

### Is this allowed?

The Actor downloads only the file URLs you provide, one plain GET each, and does not crawl, log in or bypass access controls. You are responsible for having the right to process the documents you submit. Files are processed in memory during the run and are not stored by the Actor beyond the run's dataset.

# Actor input Schema

## `urls` (type: `array`):

Direct http(s) links to PDF, PNG, JPEG, WebP or TIFF files, one per line. The file type is detected from the file itself, not from the URL. Files up to 50 MB; no login-protected links.

## `languages` (type: `array`):

Language codes of the text, e.g. en, id (Indonesian), ms, es, fr, de, pt, it, nl, tr, vi, ch (Chinese), japan. One multilingual model reads all Latin-script languages together, so listing several is fine; unknown codes are ignored with a log warning.

## `outputFormat` (type: `string`):

'text' = plain text, 'markdown' = Markdown with headings, lists and pipe tables, 'both' = both fields filled.

## `ocrMode` (type: `string`):

'auto' uses the PDF's own text layer for pages that have one (cheaper and exact) and runs OCR only on pages without it. 'always' runs OCR on every page, which helps when a PDF has a broken or hidden text layer. Images are always OCR'd.

## `quality` (type: `string`):

'accurate' uses the larger model (about 4 s per page, fewer merged words and misreads). 'fast' uses the small model (about 1 s per page). Same price either way.

## `maxPages` (type: `integer`):

Only the first N pages of each PDF (or frames of a multi-page TIFF) are processed. The row says how many pages the file has and that it was cut.

## `perPage` (type: `boolean`):

Also put the text/Markdown of every page into the 'pages' list (handy for chunking). The document-level text is always included.

## Actor input object example

```json
{
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "languages": [
    "en"
  ],
  "outputFormat": "both",
  "ocrMode": "auto",
  "quality": "accurate",
  "maxPages": 50,
  "perPage": false
}
```

# Actor output Schema

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

All results of this run (the default dataset items).

# 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 = {
    "urls": [
        "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    ],
    "languages": [
        "en"
    ],
    "maxPages": 50
};

// Run the Actor and wait for it to finish
const run = await client.actor("nelyon/pdf-image-ocr").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 = {
    "urls": ["https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"],
    "languages": ["en"],
    "maxPages": 50,
}

# Run the Actor and wait for it to finish
run = client.actor("nelyon/pdf-image-ocr").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 '{
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "languages": [
    "en"
  ],
  "maxPages": 50
}' |
apify call nelyon/pdf-image-ocr --silent --output-dataset

```

## MCP server setup

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

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/wNta6Ss6rwslXeDWL/builds/hZYuoj3OKYUdh5tGe/openapi.json
