# PDF to Text & OCR Extractor (`downright_genre/pdf-to-text-ocr`) Actor

Extract text from PDF files and scanned PDFs. Reads the text layer when present and uses OCR for image-only pages. Output per page or per document as JSON, CSV or Excel.

- **URL**: https://apify.com/downright_genre/pdf-to-text-ocr.md
- **Developed by:** [PB](https://apify.com/downright_genre) (community)
- **Categories:** Developer tools, AI, Automation
- **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 processed pdfs

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 to Text & OCR Extractor

Convert PDF to text from public URLs or uploaded files. Extract text from PDF pages with an embedded text layer, and use OCR for a scanned PDF. Choose automatic OCR, text only, or OCR for every page.

### Input

Paste public PDF URLs, upload PDFs, or use both. The example URL is filled in for a first run.

```json
{
  "pdfUrls": ["https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"],
  "ocrMode": "auto",
  "ocrLanguages": ["eng"],
  "maxPagesPerPdf": 20,
  "outputFormat": "page"
}
```

`uploadedFiles` is an optional list of file uploads or public URLs. OCR languages are `eng`, `deu`, `fra`, `spa`, `por`, and `tha`. Auto runs OCR only when a page has no extracted text. It does not detect a poor or incomplete text layer. Use `force` for those pages. `off` returns the embedded text only.

### Output

Each dataset item contains a source, page number, text, method, character count, and error. A failed PDF gets an error item and the Actor continues to the next PDF.

```json
{"source":"https://example.com/file.pdf","pageNumber":1,"text":"Hello PDF","method":"text-layer","characterCount":9,"error":null}
```

Choose `document` to combine page texts in one item. Its `pageNumber` is null and its `pages` array retains page numbers and methods. Its method can be `mixed`.

### Pricing

| Event | Price |
| --- | ---: |
| PDF processed without OCR | $0.004 per PDF |
| OCR page | $0.010 per page |
| Start fee | $0 |

A PDF that uses OCR is charged only for OCR pages. Set a maximum total charge for a run in Apify. The Actor stops when it cannot charge the next event.

### API

Replace `OWNER` and use an API token from your own account. Send the input as JSON:

```sh
curl 'https://api.apify.com/v2/acts/OWNER~pdf-to-text-ocr/runs?token=YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"pdfUrls":["https://example.com/file.pdf"],"ocrMode":"auto"}'
```

Use the returned `defaultDatasetId` to fetch the results with the [dataset items API](https://docs.apify.com/api/v2/dataset-items-get.md).

### MCP

After publication, connect to the [Apify MCP server](https://docs.apify.com/mcp.md). Find the Actor with `search-actors`, then call `call-actor` with its Actor ID and the input above. Set `maxTotalChargeUsd` in `callOptions`. Read the returned dataset with `get-dataset-items`. Availability depends on the Actor being published with limited permissions.

### Limits and FAQ

- Only public HTTP and HTTPS URLs are allowed. Private and loopback addresses are blocked, including redirects.
- Each PDF is limited to 50 MB and at most 100 pages. The default is 20 pages. Pages beyond the limit are not processed.
- Downloads time out after 60 seconds. OCR times out after 60 seconds per page. Very large pages are rejected for OCR.
- Password-protected, invalid, inaccessible, or unsupported PDFs produce an error item.
- OCR quality depends on the scan, language, and page. Text may need review.
- **Can I use several languages?** Yes. Select multiple OCR languages.
- **Why is a page empty?** It may contain no text, or OCR may not recognize it. Try `force` and check the selected languages.
- **Can I process private URLs?** No. Upload a file through Apify or supply a public URL. The upload's returned URL must be accessible to the Actor.

# Actor input Schema

## `pdfUrls` (type: `array`):

Public HTTP or HTTPS links to PDF files.

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

Auto uses OCR on pages without a text layer. Off only extracts embedded text. Force uses OCR on every page.

## `ocrLanguages` (type: `array`):

Choose one or more languages for Tesseract OCR.

## `maxPagesPerPdf` (type: `integer`):

Process at most this many pages from each PDF, up to 100.

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

Return one item per page or combine pages into one item per document.

## `uploadedFiles` (type: `array`):

Optional PDFs uploaded through Apify or public PDF URLs.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "ocrMode": "auto",
  "ocrLanguages": [
    "eng"
  ],
  "maxPagesPerPdf": 20,
  "outputFormat": "page"
}
```

# Actor output Schema

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

Dataset items with source, pageNumber, text, method (text-layer, ocr or mixed), characterCount and error.

# 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 = {
    "pdfUrls": [
        "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("downright_genre/pdf-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 = { "pdfUrls": ["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("downright_genre/pdf-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 '{
  "pdfUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ]
}' |
apify call downright_genre/pdf-to-text-ocr --silent --output-dataset

```

## MCP server setup

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