# PDF & Image to Text: OCR in Arabic, Urdu, Sinhala + 18 more (`ammartheawesome/pdf-image-text-ocr`) Actor

Extract clean text or Markdown from PDFs and images. Reads the text layer when there is one and runs OCR only on scanned pages, so you pay OCR prices only where OCR is needed. 21 OCR languages including Arabic, Urdu, Persian, Sinhala, Tamil, Hindi and Bengali.

- **URL**: https://apify.com/ammartheawesome/pdf-image-text-ocr.md
- **Developed by:** [Ammar Arquil](https://apify.com/ammartheawesome) (community)
- **Security:** 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 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

## PDF & Image to Text (OCR in 21 languages)

Turn PDFs and images into clean text or Markdown, ready for search, spreadsheets, LLMs or RAG pipelines.

- **OCR only where it's needed.** Pages with a real text layer are read directly and charged at the cheap text-page price. Only scanned pages (pages that are images with no usable text) go through OCR.
- **Non-Latin OCR included.** Arabic, Urdu, Persian, Sinhala, Tamil, Hindi, Bengali, Malay, Indonesian, Turkish, Chinese, Japanese and Korean, plus major European languages, using the open-source Tesseract engine. Mix languages in one document. Accuracy varies by script and scan quality, so test a few pages first.
- **PDFs and images in one run.** PDF, PNG, JPEG, TIFF (including multi-page), GIF, BMP and WebP.
- **Clear results for every file.** Each file returns its text, page counts, how each page was read, and a plain-English error if it couldn't be processed. One bad link never stops the rest of the run.

### How to use

1. Paste direct links to your files under **Files**. Each link must download the file itself.
2. Pick the **OCR languages** used in your documents (default: English).
3. Run. Download the results as JSON, CSV, Excel or via the API.

### Input

| Field | What it does | Default |
|---|---|---|
| Files | Direct links to PDFs or images | – |
| OCR mode | `auto` OCRs only scanned pages; `always` OCRs every page; `never` uses the text layer only | `auto` |
| OCR languages | Tesseract codes: `eng, ara, urd, fas, sin, tam, hin, ben, msa, ind, tur, fra, deu, spa, por, ita, nld, rus, chi_sim, jpn, kor` | `eng` |
| Output format | `text` or `markdown` (a title plus one heading per page) | `text` |
| Include per-page text | Adds each page's text and how it was read | on |
| Max pages per file | Pages beyond this are skipped and not charged | 200 |
| Max file size (MB) | Larger files are skipped with an error | 50 |

### Output

One item per file:

```json
{
  "url": "https://example.com/report.pdf",
  "status": "ok",
  "fileType": "pdf",
  "pageCount": 12,
  "pagesProcessed": 12,
  "truncated": false,
  "textPages": 10,
  "ocrPages": 2,
  "emptyPages": 0,
  "ocrLanguages": ["eng", "ara"],
  "format": "text",
  "characters": 18234,
  "text": "…",
  "pages": [{ "page": 1, "method": "text", "text": "…" }]
}
```

Files that can't be processed come back with `"status": "error"` and a reason in `error` (not found, too large, password-protected, not a PDF or image). **You aren't charged for failed files.**

### Pricing

You pay per page actually processed, plus a tiny fee per run:

| Event | Price |
|---|---|
| Text-layer page | $0.001 |
| OCR page | $0.004 |
| Run start (once per run) | $0.00005 |

Example: one run with a 20-page PDF that has 2 scanned pages costs 18 × $0.001 + 2 × $0.004 + $0.00005 = **$0.02605**. Set a maximum cost per run in Apify and the Actor stops cleanly when it's reached.

### Typical uses

- Make scanned contracts, invoices and reports searchable.
- Prepare PDFs for LLM or RAG pipelines (Markdown output, one heading per page).
- Digitise Arabic, Urdu, Sinhala or Tamil documents, which English-only OCR tools can't read at all.
- Bulk-convert a list of document links to JSON, CSV or Excel.

### Good to know

- Links must be publicly downloadable. Pages that need a login, and links to private or local network addresses, are refused.
- OCR quality depends on the scan. Clear scans at 200–300 DPI work best.
- Only process documents you have the right to use.

### Acceptable use

Please don't use this Actor for, or on behalf of, gambling or betting, alcohol, adult or immodest content, interest-based lending, or deceptive marketing. It's built for ordinary business, research and personal use.

# Actor input Schema

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

Direct links to PDF or image files (PNG, JPEG, TIFF, GIF, BMP, WebP). Each link must download the file itself, not a page that shows it.

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

auto: OCR only pages without a usable text layer (recommended, cheapest). always: OCR every page, e.g. when a PDF's text layer is garbled. never: text layer only, no OCR.

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

Languages in the documents, as Tesseract codes. Add every language that appears (e.g. eng and ara for an English/Arabic document). Supported: eng, ara, urd, fas, sin, tam, hin, ben, msa, ind, tur, fra, deu, spa, por, ita, nld, rus, chi_sim, jpn, kor.

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

text: plain text. markdown: a title and one heading per page, ready for LLM or RAG pipelines.

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

Also return each page's text and how it was read (text layer, OCR or empty).

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

Pages after this are skipped (and not charged). The output marks the file as truncated.

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

Larger files are skipped with an error.

## Actor input object example

```json
{
  "sources": [
    {
      "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    },
    {
      "url": "https://raw.githubusercontent.com/tesseract-ocr/test/main/testing/phototest.tif"
    }
  ],
  "ocrMode": "auto",
  "languages": [
    "eng"
  ],
  "outputFormat": "text",
  "includePages": true,
  "maxPagesPerFile": 200,
  "maxFileSizeMb": 50
}
```

# 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 = {
    "sources": [
        {
            "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
        },
        {
            "url": "https://raw.githubusercontent.com/tesseract-ocr/test/main/testing/phototest.tif"
        }
    ],
    "languages": [
        "eng"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("ammartheawesome/pdf-image-text-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 = {
    "sources": [
        { "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" },
        { "url": "https://raw.githubusercontent.com/tesseract-ocr/test/main/testing/phototest.tif" },
    ],
    "languages": ["eng"],
}

# Run the Actor and wait for it to finish
run = client.actor("ammartheawesome/pdf-image-text-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 '{
  "sources": [
    {
      "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    },
    {
      "url": "https://raw.githubusercontent.com/tesseract-ocr/test/main/testing/phototest.tif"
    }
  ],
  "languages": [
    "eng"
  ]
}' |
apify call ammartheawesome/pdf-image-text-ocr --silent --output-dataset

```

## MCP server setup

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