# PDF & Image to Text (OCR, Tables, Markdown) (`cellwright/pdf-image-to-text`) Actor

Extract clean text, tables and LLM-ready Markdown from PDFs and images. Uses the text layer when present and OCR (7 languages) only for scanned pages. Failed files are free.

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

## Pricing

Pay per event

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/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 to Text (OCR, Tables, Markdown)

Turn **PDFs and images into clean text, tables and LLM-ready Markdown** in one run. The Actor reads the PDF text layer when it exists (fast, exact) and runs **OCR only on scanned pages**, so you get the best result at the lowest price. **Failed files are free.**

Great for RAG pipelines, invoice and document processing, archive digitisation and AI agents that need to read files.

### Why this Actor

- **Hybrid extraction per page:** text layer first, OCR fallback (Tesseract, 300 DPI) only where needed.
- **Tables** detected on text pages, returned both as rows and as Markdown tables.
- **Markdown output** ready for LLMs and vector databases.
- **7 OCR languages:** English, German, French, Italian, Spanish, Portuguese, Dutch – combinable.
- **One record per file**, always: success or a clear error. 4xx URLs are not retried; network errors are retried twice.
- **Fair pricing:** pay per processed page; cheaper text-layer pages, OCR pages priced separately.

### Use cases

- **RAG and LLM pipelines** – PDFs and scans to clean Markdown with tables, ready for chunking and embeddings.
- **Invoices, receipts, delivery notes** – text and tables from digital PDFs and scanned copies in 7 languages.
- **Archive digitisation** – make scanned documents searchable in bulk.
- **Image to text** – screenshots, photos of documents and scanned pages (PNG, JPEG, TIFF, WebP, GIF, BMP).
- **AI agents** – let an agent read a PDF or image by URL.

### Input

| Field | Default | Description |
|---|---|---|
| `sources` | – | Public URLs of PDF / PNG / JPEG / TIFF / WebP / GIF / BMP files |
| `ocr` | `auto` | `auto` (scanned pages only), `always`, `never` |
| `ocrLanguages` | `["eng"]` | `eng`, `deu`, `fra`, `ita`, `spa`, `por`, `nld` |
| `extractTables` | `true` | Detect tables on text pages |
| `includePages` | `true` | Add per-page text array |
| `maxPages` | `200` | Page limit per file |
| `maxFileSizeMb` | `50` | Size limit per file (max 200) |

### Output

| Field | Description |
|---|---|
| `ok` | `true` on success; `false` with `error`, `errorType` (`input`, `blocked`, `download`) |
| `source` | Input URL |
| `type` | `pdf` or `image` |
| `text` | Full plain text |
| `markdown` | Text plus tables as Markdown |
| `tables` | `[{ page, rows: [[...]] }]` |
| `pages` | `[{ page, text, ocr, chars, tables }]` |
| `pageCount`, `pagesProcessed`, `truncated` | Page info (`truncated` if `maxPages` hit) |
| `ocrPages` | Pages that needed OCR |
| `metadata` | PDF title, subject, producer, creation date / image size |
| `chars`, `processedAt` | Text length, UTC timestamp |

### Pricing

Pay per event: **`page`** for each text-layer page, **`ocr-page`** for each page or image that needed OCR. Failed files cost nothing.

### FAQ

**How much does it cost?** USD 0.0005 per text-layer page (USD 0.50 per 1,000 pages) and USD 0.003 per page or image that needs OCR (USD 3 per 1,000), plus Apify's small actor-start fee. Failed files are free.

**Does it work with scanned PDFs?** Yes. With `ocr: auto` every page without a text layer is OCR'd automatically; digital pages keep their exact text.

**How do I keep costs low for digital PDFs?** Set `ocr: never` – only the text layer is read and only the low `page` price applies.

**Which languages does OCR support?** English, German, French, Italian, Spanish, Portuguese and Dutch. Combine them for mixed documents, e.g. `["deu", "fra", "eng"]`.

**Can it read handwriting?** No, OCR is made for printed text.

**How large can files be?** Up to 200 MB (`maxFileSizeMb`) and 2,000 pages per file (`maxPages`, default 200).

**Where do I find tables?** In `tables` (rows per page) and inside `markdown` as Markdown tables.

**Can I call it as an API?** Yes: `POST https://api.apify.com/v2/acts/cellwright~pdf-image-to-text/run-sync-get-dataset-items?token=YOUR_TOKEN` with the input JSON returns the extracted text directly.

**Do the files have to be public?** They must be reachable by URL without a login (e.g. a download or cloud storage link). Private and internal addresses are refused.

### Limits

- Public URLs only (no login); private and internal addresses are refused.
- Encrypted PDFs that forbid extraction are reported as errors.
- OCR quality depends on scan quality; handwriting is not supported.

# Actor input Schema

## `sources` (type: `array`):

Public URLs of PDF or image files (PNG, JPEG, TIFF, WebP, GIF, BMP). One output record per file.

## `ocr` (type: `string`):

auto = OCR only pages without a text layer (recommended). always = OCR every page. never = text layer only.

## `ocrLanguages` (type: `array`):

Tesseract language codes: eng, deu, fra, ita, spa, por, nld. Combine for mixed documents.

## `extractTables` (type: `boolean`):

Detect tables on text-layer pages; returned as rows and as Markdown tables.

## `includePages` (type: `boolean`):

Include a 'pages' array with text per page.

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

Stop after this many pages (you only pay for processed pages).

## `maxFileSizeMb` (type: `integer`):

Files larger than this are skipped with an error entry instead of being processed (protects you from unexpected costs).

## Actor input object example

```json
{
  "sources": [
    {
      "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    }
  ],
  "ocr": "auto",
  "ocrLanguages": [
    "eng"
  ],
  "extractTables": true,
  "includePages": true,
  "maxPages": 200,
  "maxFileSizeMb": 50
}
```

# Actor output Schema

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

One item per processed input in the default dataset (JSON, CSV, Excel via the dataset export).

# 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 = {
    "sources": [
        {
            "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("cellwright/pdf-image-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 = { "sources": [{ "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" }] }

# Run the Actor and wait for it to finish
run = client.actor("cellwright/pdf-image-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 '{
  "sources": [
    {
      "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    }
  ]
}' |
apify call cellwright/pdf-image-to-text --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,cellwright/pdf-image-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/OzJlwFogYfc8AE0n1/builds/ZZuDH5LaozP08LlS4/openapi.json
