# PDF Text Extractor & Image OCR: PDF to Text / Markdown (`trophyapps/pdf-image-to-text-ocr`) Actor

OCR and text extraction for PDFs and images: reads the PDF text layer directly and uses Tesseract OCR only for scanned pages. Text and Markdown per page; no third-party AI services.

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

## Pricing

from $3.20 / 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

## PDF Text Extractor & Image OCR: PDF to Text / Markdown

### What does PDF Text Extractor & Image OCR do?

This Actor turns **PDFs and images into clean text and Markdown**, page by page. Give it a list of file URLs and it returns the full text, a Markdown version with one heading per page, and a per-page breakdown.

- **Born-digital PDFs** (exported from Word, LaTeX, browsers, etc.): the text layer is read directly. That's fast, and returns the text as it's embedded in the PDF.
- **Scanned PDFs, photos of documents, JPEG and PNG images**: pages with no usable text layer are rendered at 300 dpi and read with the open-source **Tesseract OCR** engine.
- **OCR runs inside the Actor.** Your files are not sent to any third-party AI or OCR service.

Typical uses: feeding documents into LLM and RAG pipelines, archiving scanned paperwork, searching old reports, and extracting text from invoices or letters you're entitled to process.

### Why run it on Apify?

- Call it from your own code through the **Apify API**, or from AI agents through Apify's MCP server.
- **Schedule** recurring runs, connect results to integrations and webhooks, and download output as JSON, CSV or Excel.
- Process many files in one run; failures don't stop the batch.

### How to use it

1. Paste one or more **file URLs** (direct links to PDF, JPEG or PNG files).
2. Choose the **OCR** mode:
   - `auto` (default): OCR only for pages that are scanned images;
   - `always`: OCR every page;
   - `never`: text layer only.
3. Set the **OCR languages**, e.g. `eng` or `eng+deu`. The image includes English, German, French and Spanish.
4. Run the Actor and open the **Output** tab, or fetch the dataset through the API.

### Input example

```json
{ "fileUrls": ["https://example.com/report.pdf", "https://example.com/scan.jpg"], "ocr": "auto", "languages": "eng" }
```

### Output

One dataset item per file:

- `url` (query string removed) and `inputIndex`;
- `status`;
- `type` (`pdf` or `image`);
- `pageCount`, `textLayerPages`, `ocrPages`;
- full `text`;
- `markdown`, with a `## Page N` heading per page;
- `pages`, listing the method (`text` or `ocr`) and text for each page.

Files that can't be processed come back as rows with `status: "error"` and a reason.

### How much does it cost?

You pay **per page** (see the **Pricing** tab for current prices). Text-layer pages cost less than OCR pages, because OCR needs much more computing.

You're **never charged** for:

- OCR pages where no text is found;
- failed downloads;
- links that aren't PDFs or images;
- files above the size or page limits.

A run stops before any file that would exceed the maximum charge you set.

### Data handling

- Only **public http(s) hosts** are fetched. Private, loopback and internal addresses are refused, including after redirects.
- Each file is downloaded into the run's temporary storage, processed there, and deleted once that file is done.
- Results go to your run's Apify dataset and are kept according to your Apify account's data-retention settings.
- **Query strings are removed** from URLs in the output and the logs, so signed-URL tokens aren't copied. Use `inputIndex` to match each result to your input list.

### Accuracy and limits

- **Text-layer extraction** returns the PDF's embedded text as-is. Its quality depends on how the PDF was produced: reading order in multi-column layouts, ligatures or missing spaces can carry over.
- **OCR** is very good on clean scans. In our tests on a 19th-century book page, only minor punctuation errors appeared. It's weaker on skewed phone photos, handwriting, very small print and low-resolution images.
- Layout (columns and tables) is returned as reading-order text, not as structured tables.
- Maximum 200 MB per file; the maximum page count is configurable (default 200).
- Only process documents you have the right to use.

# Actor input Schema

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

Direct links to PDF, JPEG or PNG files.

## `ocr` (type: `string`):

auto: OCR only pages without a text layer (scans). always: OCR every page. never: text layer only.

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

Tesseract language codes joined with +. Available: eng, deu, fra, spa (e.g. eng+deu).

## `maxPages` (type: `integer`):

Longer PDFs are rejected (not charged).

## Actor input object example

```json
{
  "fileUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "ocr": "auto",
  "languages": "eng",
  "maxPages": 200
}
```

# Actor output Schema

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

One dataset item per input.

# 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://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("trophyapps/pdf-image-to-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 = { "fileUrls": ["https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"] }

# Run the Actor and wait for it to finish
run = client.actor("trophyapps/pdf-image-to-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 '{
  "fileUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ]
}' |
apify call trophyapps/pdf-image-to-text-ocr --silent --output-dataset

```

## MCP server setup

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