# PDF & Image OCR to Markdown: Scanned PDFs to Text (`rowforge/ocr-to-markdown`) Actor

Turn scanned or digital PDFs and images (PNG, JPG, TIFF, WEBP) into clean Markdown text in reading order. No API keys. $0.004 per page.

- **URL**: https://apify.com/rowforge/ocr-to-markdown.md
- **Developed by:** [Rowforge Data](https://apify.com/rowforge) (community)
- **Categories:** AI, Developer tools
- **Features:** 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 pages processed

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 OCR to Markdown: Scanned PDFs to Text

Extract text from scanned PDFs, digital PDFs and images (**PNG, JPG, WEBP, TIFF**) as clean Markdown in reading order. Use it for PDF to text and image to text conversion.

Equipped with smart layer detection: if a PDF page already has a digital text layer, the text is extracted directly at lightning speed. If a page is scanned or an image is submitted, a local CPU OCR engine reconstructs text lines and paragraphs in natural reading order.

***

### Features

- **Hybrid Extraction:** Instantly uses embedded digital text layers when present; switches to OCR for scanned pages and images.
- **Natural Reading Order:** Reconstructs lines (top-to-bottom, left-to-right) and joins them into natural paragraphs.
- **Page Headings:** Every page output starts clearly with `## Page N`.
- **SSRF Protected:** Rejects private, loopback, link-local, carrier-grade NAT, and unroutable network addresses on both DNS resolution and socket connection.
- **Reliable & Resilient:** Bad URLs or damaged files emit a clear error row without crashing the overall Actor run.
- **Pay-Per-Event:** Only pay for pages successfully processed ($0.004 per page).
- **Budget Protection:** Respects user charge limits and page caps, reporting `truncated: true` and `pagesInFile`.

***

### Pricing

$0.004 per page processed ($4 per 1,000 pages), plus a small start fee of $0.001 per GB of memory per run (about $0.002 at the default 2 GB). Pages in files that fail are not charged.

***

### Input

Configure your run via the input form or JSON:

| Field | Type | Default | Description |
|---|---|---|---|
| `urls` | Array of strings | *(Required)* | List of direct HTTP/HTTPS URLs to PDFs or images (PNG, JPG, WEBP, TIFF). Max 500 URLs per run. |
| `maxPagesPerFile` | Integer | `50` | Maximum number of pages to process per document. |
| `forceOcr` | Boolean | `false` | When true, forces OCR even if the PDF has a digital text layer. |
| `language` | String | `"en"` | Recognition model language: `en` (English), `latin` (Latin / European), `ch` (Chinese), or `devanagari` (Hindi / Devanagari). |

#### Example Input

```json
{
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
    "https://raw.githubusercontent.com/madmaze/pytesseract/master/tests/data/test.png"
  ],
  "maxPagesPerFile": 50,
  "forceOcr": false,
  "language": "en"
}
```

***

### Output

Results are stored in the run's default dataset. Each input file produces exactly one dataset row:

```json
{
  "url": "https://raw.githubusercontent.com/madmaze/pytesseract/master/tests/data/test.png",
  "status": "ok",
  "error": null,
  "fileType": "png",
  "pagesInFile": 1,
  "pageCount": 1,
  "pagesOcr": 1,
  "pagesTextLayer": 0,
  "truncated": false,
  "chars": 348,
  "seconds": 0.32,
  "markdown": "## Page 1\n\nThis is a lot of 12 point text to test the ocr code and see if it works on all types of file format.\n\nThe quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox. The quick brown dog jumped over the lazy fox."
}
```

#### Output Fields

- `url` (*string*): Source URL requested.
- `status` (*string*): `"ok"` or `"error"`.
- `error` (*string | null*): Error explanation if status is `"error"`.
- `fileType` (*string*): Detected type (`"pdf"`, `"png"`, `"jpg"`, `"webp"`, `"tiff"`).
- `pagesInFile` (*integer*): Total number of pages or frames present in the source file.
- `pageCount` (*integer*): Number of pages actually processed.
- `pagesOcr` (*integer*): Number of pages processed using OCR.
- `pagesTextLayer` (*integer*): Number of pages extracted from embedded text layers.
- `truncated` (*boolean*): `true` if processing was cut short by `maxPagesPerFile` or user charge budget limit.
- `chars` (*integer*): Length of generated Markdown text.
- `seconds` (*float*): Processing time in seconds.
- `markdown` (*string*): Formatted Markdown text.

***

### Limits

- **Input URLs limit:** Maximum 500 URLs per run. Submissions exceeding 500 unique URLs fail immediately with an exit code 1 and a descriptive error message. Blank lines are ignored, and duplicate URLs are processed only once.
- **File size:** Up to 50 MB per file. Downloads exceeding 50 MB are stopped and marked with an error row.
- **Page resolution cap:** Rendered PDF pages and loaded images are capped to 4,000 px on their longest side before OCR to prevent memory exhaustion on oversized documents.
- **Supported file formats:** PDF, PNG, JPG/JPEG, WEBP, and TIFF.
- **Timeouts:** 120 seconds total download deadline per URL covering redirects and body.
- **Protocol:** HTTP and HTTPS only. Non-globally routable addresses (127.0.0.1, 10.0.0.0/8, 100.64.0.0/10, 169.254.0.0/16, 192.0.0.0/24, 198.18.0.0/15, multicast, link-local, private) are strictly refused at connect time with IP pinning to prevent DNS rebinding.
- **Page cap:** Default 50 pages per file (customizable via `maxPagesPerFile`, minimum 1, maximum 500). Files exceeding the page limit are truncated with `truncated: true`. If processing fails part-way through a file, pages already processed are preserved with `status: "ok"`, `truncated: true`, and the failed page named in `error`.

***

### Supported Languages

- **`en` (English, default):** General English Latin text, digits, and punctuation.
- **`latin` (Latin / European):** European languages with diacritics and accents (e.g. French, German, Spanish, Portuguese — *café über niño*).
- **`ch` (Chinese):** Simplified Chinese character recognition.
- **`devanagari` (Hindi / Devanagari):** Hindi and Sanskrit Devanagari script (e.g. *भारत*, *नमस्ते*).

***

### What This Actor Does Not Do

- **Handwriting:** Optimized for machine-printed text, receipts, scans, and documents; unconstrained cursive handwriting is not supported.
- **Tables as Tables:** Table contents are extracted line-by-line in natural reading order; grid/cell table reconstruction as Markdown syntax pipes (`|---|`) is not performed.
- **Non-HTTP URIs:** Does not accept local file paths (`file://`), FTP, or internal intranet IPs.

# Actor input Schema

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

List of direct public URLs to PDFs or images (PNG, JPG, WEBP, TIFF) to convert to Markdown.

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

Maximum number of pages to process per PDF file (safeguard for long documents).

## `forceOcr` (type: `boolean`):

If true, run optical character recognition even on PDF pages that already contain a digital text layer.

## `language` (type: `string`):

Recognition model language.

## Actor input object example

```json
{
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
    "https://raw.githubusercontent.com/madmaze/pytesseract/master/tests/data/test.png"
  ],
  "maxPagesPerFile": 50,
  "forceOcr": false,
  "language": "en"
}
```

# Actor output Schema

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

Dataset containing OCR and Markdown extraction results for all processed URLs.

# 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 = {
    "urls": [
        "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
        "https://raw.githubusercontent.com/madmaze/pytesseract/master/tests/data/test.png"
    ],
    "language": "en"
};

// Run the Actor and wait for it to finish
const run = await client.actor("rowforge/ocr-to-markdown").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 = {
    "urls": [
        "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
        "https://raw.githubusercontent.com/madmaze/pytesseract/master/tests/data/test.png",
    ],
    "language": "en",
}

# Run the Actor and wait for it to finish
run = client.actor("rowforge/ocr-to-markdown").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 '{
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
    "https://raw.githubusercontent.com/madmaze/pytesseract/master/tests/data/test.png"
  ],
  "language": "en"
}' |
apify call rowforge/ocr-to-markdown --silent --output-dataset

```

## MCP server setup

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

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/n0Dr1t7wr0EbIcGbG/builds/0JbMdjuZCR8Ag97Ew/openapi.json
