# Image & PDF OCR (Tesseract): text from scans, photos and PDFs (`fecklesspleb/image-pdf-ocr`) Actor

Extract text from image and PDF URLs with Tesseract OCR: plain text, lines with confidence and position, 8 languages. PDF pages that already have a text layer skip OCR. No API key. $2 per 1,000 OCR pages.

- **URL**: https://apify.com/fecklesspleb/image-pdf-ocr.md
- **Developed by:** [fecklesspleb](https://apify.com/fecklesspleb) (community)
- **Categories:** Developer tools, AI
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.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/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

## Image & PDF OCR (Tesseract)

Turn scans, photos of documents and image-only PDFs into text. Give it file URLs and get one result per page: the text, each line with its confidence and position, and optionally every word. PDF pages that already have a text layer are read directly, with no OCR, so you pay the lower text-layer price.

- Engine: [Tesseract](https://github.com/tesseract-ocr/tesseract) 5, running inside the Actor. No API key, no external OCR service.
- Languages: English, German, French, Spanish, Italian, Portuguese, Dutch, Polish. You can combine several.
- Inputs: PNG, JPEG, GIF, TIFF (including multi-page), WebP, BMP and PDF.

Empty input runs a free demo on 3 bundled sample pages, so you can see the output first.

### Input

| Field | Default | Notes |
|---|---|---|
| `urls` | empty (= demo) | Direct file links. Only use files you have the right to process. |
| `languages` | `["eng"]` | One or more of `eng deu fra spa ita por nld pol`. |
| `pdfMode` | `auto` | `auto`: a page's own text layer if it has at least `minTextLayerChars` non-space characters, otherwise OCR. `ocr`: always OCR. `text`: text layer only. |
| `minTextLayerChars` | 20 | Threshold for `auto`. |
| `dpi` | 200 | Render resolution for PDF pages (72-400). |
| `psm` | `"3"` | Tesseract page segmentation mode: 3 auto, 4 single column, 6 one block, 11/12 sparse text, 1 auto with orientation detection. |
| `includeLines` | true | Lines with mean confidence and `bbox` `[x, y, width, height]` in pixels of the OCR image. |
| `includeWords` | false | Every word with confidence and bbox. |
| `maxPagesPerFile` | 20 | Pages or frames per file (1-500). |
| `maxFiles` | 100 | |
| `maxFileSizeMb` | 25 | Bigger files are skipped, free of charge. |
| `concurrency` | 2 | Files processed in parallel. |

### Output

One dataset item per page:

`url`, `finalUrl` (after redirects), `fileIndex`, `fileType` (`image`/`pdf`), `page`, `pageCount`, `method` (`ocr`/`text-layer`), `languages`, `text`, `wordCount`, `charCount`, `meanConfidence` (0-100, OCR only), `lines`, `words`, `width`, `height`, `dpi`, `ocrSeconds`, `status`.

Files that cannot be used produce one free item with `"type": "status"` saying why, and the run continues. Reasons include: a download error, robots.txt disallows the URL, not an image or PDF, too big, or a damaged file. `RUN_SUMMARY` in the key-value store has the counts.

### Examples (real local runs, 2026-11-11, Tesseract 5.5.0, eng)

**1. `{"urls": ["https://raw.githubusercontent.com/tesseract-ocr/test/main/testing/phototest.tif"]}`.** This is a test image from the Tesseract project's Apache-2.0 test repository. Output (`finalUrl`, `fileIndex` and `ocrSeconds` left out, and only the first two lines shown):

```json
{
 "url": "https://raw.githubusercontent.com/tesseract-ocr/test/main/testing/phototest.tif",
 "fileType": "image", "page": 1, "pageCount": 1, "method": "ocr", "languages": ["eng"],
 "text": "This is a lot of 12 point text to test the\nocr code and see if it works on all types\nof file format.\n\nThe quick brown dog jumped over the\nlazy fox. The quick brown dog jumped\nover the lazy fox. The quick brown dog\njumped over the lazy fox. The quick\nbrown dog jumped over the lazy fox.",
 "wordCount": 60, "charCount": 285, "meanConfidence": 96.2, "width": 640, "height": 480,
 "lines": [
  {"text": "This is a lot of 12 point text to test the", "confidence": 96.3, "bbox": [36, 92, 544, 30]},
  {"text": "ocr code and see if it works on all types", "confidence": 95.1, "bbox": [36, 126, 582, 31]}
 ],
 "status": "ok"
}
```

**2. Empty input (`{}`), the demo.** 3 pages, no charge:

- `demo:sample-scan.png`, OCR, confidence 94.8: `"SAMPLE INVOICE 2026-0042\nItem: Office chair, qty 2\nUnit price: 125.00\n\nTotal due: 250.00\n\nThank you for your business."`
- `demo:sample-scan.pdf` (image-only PDF), OCR at 200 DPI, confidence 96.4: `"SCANNED LETTER\n\nThe meeting moved to Thursday at 10:00.\nPlease bring the signed form."`
- `demo:sample-text-layer.pdf`, `method: "text-layer"`: `"Release notes, version 1.2\nThis page has a real text layer,\nso pdfMode auto reads it without OCR."`

**3. A missing file:** `https://raw.githubusercontent.com/tesseract-ocr/test/main/testing/does-not-exist.png` gives a free status item: `"...does-not-exist.png: HTTP 404. Nothing was charged for this file."`

### Pricing

| Event | Price |
|---|---|
| `page-ocr`: one page or image frame OCR-ed | $0.002 ($2 per 1,000) |
| `page-text-layer`: one PDF page read from its text layer | $0.0005 |
| `apify-actor-start`: Apify's standard run start (one per GB of memory, so 1 at the default 1,024 MB) | $0.00005 |
| Failed files, status items, demo | free |

The run stops before starting a page it could not charge within your **maximum charge per run**.

### Accuracy and limits

- Tesseract works best on clean printed text. Photos at an angle, low resolution, handwriting and decorative fonts give lower `meanConfidence` and more errors.
- Images over 40 megapixels are scaled down before OCR.
- Each page has a 120 s OCR time limit.
- Encrypted (password-protected) PDFs are not opened.

### Fetching rules

- Only http(s) URLs. URLs that point to private or local network addresses, or that contain a user name or password, are refused.
- Each host's `robots.txt` is read and obeyed, for the `ImagePdfOcrActor` user agent and `*`. If it cannot be read (server error or an HTML page), the file is not fetched.
- Redirects are followed (at most 5), and each hop is checked again.
- No cookies, no logins, no proxy, no anti-bot workarounds.

### Licences (evidence copies in `evidence/`, read 2026-11-11)

- Tesseract, https://raw.githubusercontent.com/tesseract-ocr/tesseract/main/LICENSE: "Apache License Version 2.0, January 2004".
- Language data:
  - Debian's `tesseract-ocr-eng` copyright file: "Upstream-Name: tessdata_fast ... License: Apache-2.0".
  - https://raw.githubusercontent.com/tesseract-ocr/tessdata_fast/main/LICENSE: "Apache License Version 2.0".
- Leptonica (Tesseract's image library), https://raw.githubusercontent.com/DanBloomberg/leptonica/master/leptonica-license.txt: a BSD-style licence ("Redistribution and use in source and binary forms, with or without modification, are permitted provided that...").
- pypdfium2, https://github.com/pypdfium2-team/pypdfium2 README "Licensing": "pypdfium2 itself is available by the terms and conditions of Apache-2.0 / BSD-3-Clause". It also says "PDFium is available under 'a BSD-style license'".
- Pillow, https://raw.githubusercontent.com/python-pillow/Pillow/main/LICENSE: "Pillow is licensed under the open source MIT-CMU License".
- Example 1's image comes from https://github.com/tesseract-ocr/test, whose LICENSE file is "Apache License Version 2.0". The demo files were made by us (`bench/make_samples.py`).

# Changelog

This Actor's version history is a separate document: https://apify.com/fecklesspleb/image-pdf-ocr/changelog.md

# Actor input Schema

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

Direct links to PNG, JPEG, GIF, TIFF (multi-page too), WebP, BMP or PDF files that you have the right to process. Each host's robots.txt is respected. Private/local network addresses and URLs with a user name or password are not fetched. Leave empty to run the free bundled demo (3 sample pages).

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

Language(s) of the text. Several languages are combined (slower).

## `pdfMode` (type: `string`):

auto = use the PDF's own text layer when a page has one (cheaper, exact), OCR the other pages. ocr = always OCR. text = text layer only, never OCR.

## `minTextLayerChars` (type: `integer`):

In auto mode, a page's text layer is used when it has at least this many non-space characters.

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

Resolution used to render PDF pages for OCR. 200 suits most scans; 300 helps small print but is slower.

## `psm` (type: `string`):

Tesseract page segmentation mode. 3 (automatic) suits most pages.

## `includeLines` (type: `boolean`):

When on, each page item includes a list of text lines with mean confidence and bounding box \[x, y, width, height] in pixels of the OCR image.

## `includeWords` (type: `boolean`):

When on, each page item includes every word with confidence and bounding box. Off by default (larger output).

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

Maximum pages or frames processed per file (PDF pages or multi-page TIFF/GIF frames). Further pages are skipped.

## `maxFiles` (type: `integer`):

Process at most this many input URLs. Further files are skipped.

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

Files larger than this are skipped and not charged.

## `concurrency` (type: `integer`):

How many files to process in parallel.

## Actor input object example

```json
{
  "languages": [
    "eng"
  ],
  "pdfMode": "auto",
  "minTextLayerChars": 20,
  "dpi": 200,
  "psm": "3",
  "includeLines": true,
  "includeWords": false,
  "maxPagesPerFile": 20,
  "maxFiles": 100,
  "maxFileSizeMb": 25,
  "concurrency": 2
}
```

# Actor output Schema

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

No description

## `summary` (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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("fecklesspleb/image-pdf-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 = {}

# Run the Actor and wait for it to finish
run = client.actor("fecklesspleb/image-pdf-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 '{}' |
apify call fecklesspleb/image-pdf-ocr --silent --output-dataset

```

## MCP server setup

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