# OCR Text Extractor – Images & Scanned PDF to Text (`musclenerd/ocr-text-extractor`) Actor

Extract text from images and scanned PDFs with Tesseract OCR. Text-based PDF pages are read directly and cost less. Output as plain text or markdown with a confidence score.

- **URL**: https://apify.com/musclenerd/ocr-text-extractor.md
- **Developed by:** [andrei franc](https://apify.com/musclenerd) (community)
- **Categories:** Developer tools, AI, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 ocr pages

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 Text Extractor – Images & Scanned PDF to Text

Turn images and scanned PDFs into text. Give it a list of file URLs and get one dataset item per page, with the extracted text, the method used and an OCR confidence score. Built on Tesseract OCR and Poppler, running inside the Actor, so there are no external API keys and your files are only fetched from the URLs you provide.

PDF pages that already contain text are read directly from the file. They need no OCR, so they cost much less. You pay the OCR price only for pages that really need OCR.

### What can you do with it?

- Digitise archives of scanned documents, letters, contracts and reports.
- Read text from screenshots, photos of documents and image exports.
- Prepare clean text or markdown for search, RAG pipelines and LLM prompts.
- Process mixed PDFs: pages with a text layer and scanned pages in the same file.
- Run recurring batch jobs through the Apify API, schedules or integrations.

### How it works

1. The Actor downloads each file (max 50 MB, 60 second timeout) and detects the type from its content.
2. Images go straight to Tesseract.
3. PDF pages are checked one by one. In `auto` mode a page with a text layer is read with `pdftotext`. A page without text is rendered with `pdftoppm` at the DPI you choose and then OCR'd.
4. Each page becomes one dataset item. A failing file or page never stops the run: it is reported in the item's `error` field and is not charged.

Supported formats: PDF, PNG, JPG/JPEG, TIFF, WebP, BMP.
Supported languages: English (`eng`), Italian (`ita`), German (`deu`), French (`fra`), Spanish (`spa`), Portuguese (`por`). Select several languages for mixed-language documents.

### Input

| Field | Description |
| --- | --- |
| `fileUrls` | Required. Public URLs of images or PDFs. |
| `languages` | Languages in the document. Default `["eng"]`. |
| `pages` | PDF only. Page selection such as `1-3,5`. Empty means all pages. |
| `maxPagesPerFile` | Safety limit per PDF. Default 20. |
| `ocrMode` | `auto` (default) reads text-based pages directly; `always` OCRs every PDF page. |
| `dpi` | Render resolution for scanned PDF pages, 100-400. Default 300. |
| `outputFormat` | `text` (default) or `markdown` (wrapped lines joined into paragraphs). |

Example input:

```json
{
    "fileUrls": [
        "https://example.com/scans/invoice-0042.pdf",
        "https://example.com/images/letter.png"
    ],
    "languages": ["eng", "ita"],
    "maxPagesPerFile": 10,
    "outputFormat": "markdown"
}
```

### Output

One item per page (or per image):

```json
{
    "sourceUrl": "https://example.com/scans/invoice-0042.pdf",
    "fileType": "pdf",
    "page": 1,
    "method": "ocr",
    "languages": ["eng", "ita"],
    "text": "Invoice no. 0042 ...",
    "confidence": 93.4,
    "charCount": 1280
}
```

- `method` is `ocr` or `text-layer`.
- `confidence` is the mean word confidence from 0 to 100 (OCR pages only). Low values mean a poor scan: try `dpi` 400.
- A summary per file (pages, OCR pages, text-layer pages, errors) is saved in the key-value store under `SUMMARY`.

Export the dataset as JSON, CSV, Excel or HTML, or read it through the Apify API.

### Pricing

Pay per event, no subscription:

| Event | Price |
| --- | --- |
| OCR page (an image or a scanned PDF page) | $0.005 |
| Text-layer page (PDF page read without OCR) | $0.0005 |

That is $5 per 1,000 OCR pages. Pages that fail are not charged. You can cap spending with the maximum cost per run setting; the Actor stops cleanly when the limit is reached.

### Limits

- Handwriting is not supported. Tesseract works on printed text.
- Quality depends on the scan: skewed, blurred or very low-resolution files give lower confidence.
- Tables are returned as text, not as structured cells. For tables in text-based PDFs see the [PDF Table Extractor](https://apify.com/musclenerd/pdf-tables-extractor) Actor.
- Password-protected PDFs are not supported.

### FAQ

**Does it work on PDFs that mix scanned and text pages?** Yes. In `auto` mode each page is handled on its own.

**Can I force OCR on a PDF that has a text layer?** Yes, set `ocrMode` to `always`.

**Is my data stored?** Files are downloaded to temporary storage during the run and deleted when each file is done. Results stay in your Apify dataset.

### Responsible use

Only process files you have the right to use. Documents can contain personal data: you are responsible for handling the extracted text in line with the law that applies to you, including GDPR. This Actor is maintained by an AI agent; report problems through the Issues tab.

# Actor input Schema

## `fileUrls` (type: `array`):

Public links to images (PNG, JPG, TIFF, WebP, BMP) or PDF files, scanned or text-based. One URL per file, up to 50 MB each.

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

Languages in the document. Pick every language that appears in the text: eng, ita, deu, fra, spa, por.

## `pages` (type: `string`):

Optional page selection for PDFs, for example "1-3,5". Empty means all pages (up to the limit below).

## `maxPagesPerFile` (type: `integer`):

Safety limit on the number of PDF pages processed (and charged) per file.

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

auto: PDF pages that already contain text are read directly (cheaper, no OCR); pages without text are OCR'd. always: run OCR on every PDF page.

## `dpi` (type: `integer`):

Resolution used to render scanned PDF pages before OCR. 300 suits most documents; 400 helps with small print.

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

text: keeps the line breaks of the page. markdown: joins wrapped lines into paragraphs separated by a blank line (handy for RAG and LLM input).

## Actor input object example

```json
{
  "fileUrls": [
    "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/linn.png",
    "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/multipage.pdf"
  ],
  "languages": [
    "eng"
  ],
  "maxPagesPerFile": 20,
  "ocrMode": "auto",
  "dpi": 300,
  "outputFormat": "text"
}
```

# 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 = {
    "fileUrls": [
        "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/linn.png",
        "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/multipage.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("musclenerd/ocr-text-extractor").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 = { "fileUrls": [
        "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/linn.png",
        "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/multipage.pdf",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("musclenerd/ocr-text-extractor").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 '{
  "fileUrls": [
    "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/linn.png",
    "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/multipage.pdf"
  ]
}' |
apify call musclenerd/ocr-text-extractor --silent --output-dataset

```

## MCP server setup

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

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/b0I0kLXwrOAeR3auF/builds/ZBpRCJtuOhzPtzcSS/openapi.json
