# Image to Text & PDF to Text OCR (English + Arabic) (`runekit/arabic-document-ocr`) Actor

Extract text from images, screenshots, and scanned or digital PDFs by URL or Key-Value Store. English & Arabic OCR + digit normalization. Unreadable pages $0.

- **URL**: https://apify.com/runekit/arabic-document-ocr.md
- **Developed by:** [Runekit](https://apify.com/runekit) (community)
- **Categories:** AI, Automation, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 87.5% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.90 / 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.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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 to Text & PDF to Text OCR (English + Arabic)

Author: **Runekit**

Extract Arabic and English text from scans, screenshots, and PDFs you supply. Each page becomes one dataset row. Unreadable pages are not charged. The actor does not browse or scrape websites.

This is printed-text OCR. It is not an invoice, VAT, or totals extractor. Phone photos and difficult captures can be weaker than clean scans.

### Use cases

1. Turn scanned Arabic or bilingual PDFs into searchable text for a document pipeline or archive.
2. OCR screenshots or photos of printed forms, letters, notices, or book pages.
3. Keep a PDF's existing text layer when it already has real text, and run OCR only on scanned or empty pages.

### Example output

One dataset item per page:

```json
{
  "fileUrl": "https://example.com/page.png",
  "fileName": "page.png",
  "pageNumber": 1,
  "totalPages": 1,
  "method": "ocr",
  "language": "ara+eng",
  "text": "NUMBER OF NOUNS.\nThe number of nouns is either singular, dual, or plural.",
  "textNormalized": "NUMBER OF NOUNS.\nThe number of nouns is either singular, dual, or plural.",
  "confidence": 88.4,
  "wordCount": 180,
  "charCount": 1100,
  "passes": 1,
  "pass": "raw",
  "charged": true,
  "chargeSkippedReason": null,
  "error": null
}
```

`text` is the text as read. `textNormalized` is the same text with Arabic-Indic digits (`٠١٢٣٤٥٦٧٨٩`) and Persian digits (`۰۱۲۳۴۵۶۷۸۹`) converted to `0-9`. `method` is `ocr` or `text-layer`.

### Pricing

Pay per event. The price follows the Apify Store discount tier. No charge is made per dataset item. A stored page is billed on one event only, and only when `charged` is true.

| Event | When it is charged | Free | Bronze | Silver | Gold, Platinum, Diamond |
| --- | --- | --- | --- | --- | --- |
| `ocr-page` | Each page that needs OCR | $0.003 | $0.0026 | $0.0022 | $0.0019 |
| `text-layer-page` | PDF page that already has a text layer, extracted without OCR | $0.0005 | $0.00045 | $0.0004 | $0.00035 |
| `apify-actor-start` | Per run | $0.0005 | $0.0005 | $0.0004 | $0.0004 |

$3.00 / 1,000 OCR pages on Free, $1.90 on Gold, Platinum, and Diamond. $0.50 / 1,000 text-layer pages on Free, $0.35 on Gold, Platinum, and Diamond.

`ocr-page` and `text-layer-page` are the two page events. A billed PDF page read from its text layer is `text-layer-page`. Any other billed page is `ocr-page`. Apify charges `apify-actor-start` automatically: one charge per run at up to 1 GB of memory, then one more charge for each extra GB. Unreadable pages are not charged (`chargeSkippedReason` may be `empty`, `low-confidence`, `non-text`, or `error`).

### Input

| Field | Default | Meaning |
| --- | --- | --- |
| `files` | one public sample page | HTTP(S) URLs of PDFs or images (JPEG, PNG, WEBP, TIFF, BMP), 25 MB or smaller each |
| `sourceKeyValueStore` | (none) | The key-value store that holds your files. Pick it in **Key-value store with your files** so a limited-permissions run can read it. The actor only reads that store and never writes to it. Leave this empty to use this run's default store. |
| `keyValueStoreRecords` | (none) | A record key in the store you picked, or in this run's default store when no store is picked. `storeIdOrName/recordKey` still works when this run can already read that store (store id, store name, or username~store-name). If it cannot, that item asks you to pick the store and the other files still run. The key must match exactly. A missing record is an error on that item. Images and PDFs are read as raw bytes. The actor does not write the file back. |
| `languages` | `ara+eng` | Tesseract languages: `ara`, `ara+eng`, or `eng` |
| `preprocess` | `true` | EXIF rotation, then one greyscale read capped at 2400 px (2000 px with illumination on an uneven photo when the text stays large enough). Extra cleanup runs only in accurate mode |
| `accurateMode` | `false` | Slower, more passes. The page price is the same. |
| `skipOcrWhenTextLayer` | `true` | Keep a non-empty PDF text layer instead of OCR'ing that page |
| `maxPagesPerFile` | `20` | Page cap per PDF or multi-page TIFF (maximum 200) |
| `extractFields` | `false` | Experimental, printed invoices only (see below) |
| `psm` | `3` | Tesseract page segmentation mode |
| `renderDpi` | `300` | DPI used when a PDF page is rendered for OCR (150–400) |

A limited-permissions run cannot read a key-value store that is only named in a text field. Pick that store in **Key-value store with your files**. The platform then allows this run to read it. A plain key such as `scan.png` is read from the store you picked. `invoices/scan.png` still names a store and a key. When that store is the one you picked, the file is read from it. When it is a different store, the actor tries the named store. If the run is not allowed to read it, that item gets an error and the other files still run.

### Field candidates (experimental)

`extractFields` stays off by default. When on, the actor may add a `fields` object with pattern matches for dates, Hijri dates marked with `هـ`, Saudi VAT-like numbers, currency amounts, and total lines. These are experimental, intended for printed invoices only, and are not verified values.

### Limits

- Handwriting is not supported.
- Accuracy depends on the scan: resolution, contrast, skew, and how clean the print is. Phone photos are often weaker than clean scans or screenshots.
- With `skipOcrWhenTextLayer` on, a non-empty PDF text layer is kept even when that text is incomplete or wrong.
- BMP files go to Tesseract as they are (no Sharp preprocessing).
- Animated WEBP uses the first frame only.
- URLs must be `http` or `https`. The downloader blocks private, loopback, link-local, and metadata addresses.
- The actor can run from 512 MB to 2048 MB. Give long documents more memory.

### Privacy

Source files are downloaded into a temporary directory and deleted after each file finishes, including when the file fails. They are never written to the key-value store. When you pick a source key-value store, the actor only reads the records you list and does not write to that store. The dataset keeps the extracted text for the account's data-retention period. The original file bytes are not stored.

### Run locally

The Docker image is the supported runtime. A local `apify run` needs `tesseract` with `ara`, `eng`, and `osd` traineddata, plus `pdfinfo`, `pdftotext`, and `pdftoppm`.

```bash
npm install
npm test
apify run --input-file input.example.json
```

# Actor input Schema

## `files` (type: `array`):

HTTP or HTTPS URLs of PDFs or images you supply. Supported types: PDF, JPEG, PNG, WEBP, TIFF, and BMP. Each file must be 25 MB or smaller.

## `sourceKeyValueStore` (type: `string`):

The key-value store that holds your images and PDFs. Pick it here so a limited-permissions run can read it. The actor only reads that store and never writes to it. Leave this empty to use this run's default store.

## `keyValueStoreRecords` (type: `array`):

Record keys to read. A plain key is read from the store you picked in "Key-value store with your files", or from this run's default store when that field is empty. storeIdOrName/recordKey (a store id, store name, or username~store-name) still works when this run can already read that store. If it cannot, that item asks you to pick the store in "Key-value store with your files" and the other files still run. The key must match exactly. A missing record is an error on that item. Images and PDFs are read as raw bytes. The actor does not write the file back.

## `languages` (type: `string`):

Tesseract traineddata. ara+eng is the default. Use ara for Arabic-only pages or eng for English-only pages.

## `preprocess` (type: `boolean`):

When on, the page is EXIF-rotated and read once as greyscale. The long side is capped at 2400 pixels and smaller images are not enlarged. A shadowed photo is illumination-corrected and, when the text is still large enough, capped at 2000 pixels. Accurate mode can still run cleanup and a second read. When off, there is no EXIF rotation and no cleanup pass. The long-side cap still applies. DPI comes from a stored density of 150 to 600, scaled when the page is reduced, from a text-line estimate, or as 300 when that estimate cannot be made. BMP files skip Sharp.

## `accurateMode` (type: `boolean`):

Slower, more passes. The page price is the same.

## `skipOcrWhenTextLayer` (type: `boolean`):

When enabled, a PDF page with a non-empty text layer is copied from that layer and not OCR'd. Whitespace-only pages are still OCR'd. A non-empty text layer is kept even if the extracted text is wrong.

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

Maximum pages read from each PDF or multi-page TIFF. Later pages are skipped.

## `extractFields` (type: `boolean`):

Experimental, printed invoices only. When on, adds best-effort candidate dates, Saudi VAT numbers, currency amounts, and total lines. These are pattern matches, not verified values. Leave off for ordinary text OCR.

## `psm` (type: `integer`):

Page segmentation mode passed to Tesseract. 3 is Tesseract's default; 0 is OSD-only; 2 is not implemented; 6 is a single block.

## `renderDpi` (type: `integer`):

Resolution used when a PDF page is rendered for OCR. 300 is the default. 150 to 400 are allowed.

## Actor input object example

```json
{
  "files": [
    "https://raw.githubusercontent.com/py-pdf/fpdf2/master/test/text_shaping/bidi_arabic_lorem_ipsum.pdf"
  ],
  "languages": "ara+eng",
  "preprocess": true,
  "accurateMode": false,
  "skipOcrWhenTextLayer": true,
  "maxPagesPerFile": 20,
  "extractFields": false,
  "psm": 3,
  "renderDpi": 300
}
```

# Actor output Schema

## `dataset` (type: `string`):

One dataset item per page.

# 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 = {
    "files": [
        "https://raw.githubusercontent.com/py-pdf/fpdf2/master/test/text_shaping/bidi_arabic_lorem_ipsum.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("runekit/arabic-document-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 = { "files": ["https://raw.githubusercontent.com/py-pdf/fpdf2/master/test/text_shaping/bidi_arabic_lorem_ipsum.pdf"] }

# Run the Actor and wait for it to finish
run = client.actor("runekit/arabic-document-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 '{
  "files": [
    "https://raw.githubusercontent.com/py-pdf/fpdf2/master/test/text_shaping/bidi_arabic_lorem_ipsum.pdf"
  ]
}' |
apify call runekit/arabic-document-ocr --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,runekit/arabic-document-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/scK8j57eHYaD0rDla/builds/HZNMaGJ56UBZOPpSs/openapi.json
