# PDF Text Extractor & OCR: PDF and Scanned PDF to Text (`spellzcode/pdf-to-text-extractor`) Actor

Turn PDFs into clean text for search, analysis and AI pipelines. Give it PDF links and get each document's full text, page-by-page text, word and page counts and metadata. Scanned pages can be read with OCR in 12 languages.

- **URL**: https://apify.com/spellzcode/pdf-to-text-extractor.md
- **Developed by:** [Mårten Fitzback](https://apify.com/spellzcode) (community)
- **Categories:** AI, Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.50 / 1,000 pdf extracteds

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 & OCR: PDF and Scanned PDF to Text

Give it links to PDF files and get back each document's text, ready for search, analysis or an AI pipeline. Scanned PDFs, which are pictures of pages, can be read with OCR.

**You pay only for PDFs whose text was extracted.** Links that are broken, are not PDFs, or are password-protected come back with a status and cost nothing. OCR is off unless you switch it on, and it is charged only for the pages that actually need it.

### What you get for each PDF

| Field | What it is |
|---|---|
| `text` | The full text, pages separated by a blank line, with words that were hyphenated across line breaks rejoined |
| `pages` | Optional: the text of each page separately, with its page number and whether it came from stored `text` or from `ocr` |
| `pageCount`, `wordCount`, `characterCount` | Size of the document |
| `title`, `author`, `subject`, `creator`, `producer` | The document's own metadata |
| `createdAt`, `modifiedAt` | Document dates in standard format |
| `looksScanned` | `true` when nearly every page had no stored text, which means the PDF is images of text |
| `ocrPageCount`, `ocrConfidence` | How many pages were read with OCR, and the OCR engine's own confidence from 0 to 100 |
| `ocrIncomplete` | `true` when some scanned pages were left unread because of your page limit or spending limit |
| `status` | `ok`, `download-failed`, `not-a-pdf`, `unreadable` or `invalid-input` |

### Scanned PDFs and OCR

Turn on **Read scanned pages with OCR** and every page without stored text is drawn at 300 dots per inch and read with Tesseract, an open-source OCR engine. Pages that already have text are left alone and are never charged for OCR, so a PDF that mixes typed and scanned pages costs only for the scanned ones.

- **Languages:** English, German, French, Spanish, Italian, Portuguese, Dutch, Swedish, Danish, Norwegian, Finnish and Polish. Pick the language of the document for the best result.
- **Tables:** each table row comes out as one line of text, in reading order.
- **What to expect:** clean printed text is read reliably. In our own test page, ordinary typefaces were read without error, while an old-style typeface whose digits vary in height had a 9 misread as 0. If figures matter, check them, and treat a low `ocrConfidence` as a warning.
- **Not suitable for:** handwriting, and photos of pages taken at an angle or in poor light.

### Input

```json
{
  "pdfUrls": ["https://arxiv.org/pdf/1706.03762"],
  "includePages": true,
  "ocrScanned": true,
  "ocrLanguage": "eng",
  "maxOcrPages": 50
}
```

`maxOcrPages` is the most pages read with OCR in one PDF. It keeps the cost of a long scanned document predictable.

### Output example

```json
{
  "url": "https://arxiv.org/pdf/1706.03762",
  "status": "ok",
  "pageCount": 15,
  "wordCount": 6462,
  "looksScanned": false,
  "ocrPageCount": 0,
  "ocrConfidence": null,
  "title": "Attention Is All You Need",
  "text": "Attention Is All You Need\n..."
}
```

### Pricing

$5.00 per 1,000 PDFs ($0.005 each). One charge per PDF whose text was extracted, whatever its length.

OCR, when switched on, adds $8.00 per 1,000 scanned pages ($0.008 each). Pages with stored text are never charged for OCR.

200 ordinary PDFs cost $1. A 30-page scanned contract read with OCR costs $0.245: $0.005 for the PDF and $0.24 for its pages.

Each run also has a start charge of $0.00005. There is no separate charge for computing time. Apify's paid plans get 10% to 30% off these prices; the Pricing tab shows yours. Apify's free plan includes $5 of credit a month, which covers 1,000 ordinary PDFs or about 600 scanned pages.

### Limits

- Without OCR it reads only the text stored in the PDF. Scanned documents then come back with empty text and `looksScanned` set to `true`.
- OCR reads printed text in the twelve languages listed above. It does not read handwriting.
- Files up to 40 MB. Text beyond 4 million characters is cut and the item is marked `truncated`.
- Tables come out as lines of text, not as structured rows and columns.

### Questions

#### Can I run it on a schedule?

Yes. Save your input as a task and add an Apify schedule, for example every morning.

#### How do I get the results into Excel or Google Sheets?

Every run's results can be downloaded as Excel, CSV or JSON from the run's Output tab. Apify's integrations with Make, Zapier, n8n and Google Sheets can pass them on automatically.

#### Can I call it from my own code or from an AI agent?

Yes. The API tab has ready-made code for Python, JavaScript and cURL, and the tool can be connected to AI agents through Apify's MCP server.

#### Does OCR cost anything if my PDFs are not scanned?

No. With OCR switched on, only pages that have no stored text are read and charged.

#### Something looks wrong or is missing

Open a report under the Issues tab and include the input you used.

# Actor input Schema

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

Links to PDF files, one per line. Each file can be up to 40 MB.

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

Adds a list with one entry per page, useful for citing page numbers or splitting a document into chunks.

## `ocrScanned` (type: `boolean`):

Scanned pages are pictures of text and have no stored text. Turn this on to read them with optical character recognition. Each page read this way has its own charge; pages that already have text are never charged for OCR.

## `ocrLanguage` (type: `string`):

Used only when OCR is on. Choosing the right language improves accuracy for accented letters.

## `maxOcrPages` (type: `integer`):

A limit that keeps the cost of a long scanned document predictable. Pages beyond it are left empty and the document is marked as incomplete.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://arxiv.org/pdf/1706.03762"
  ],
  "includePages": false,
  "ocrScanned": false,
  "ocrLanguage": "eng",
  "maxOcrPages": 50
}
```

# Actor output Schema

## `documents` (type: `string`):

One item per PDF: full text, optional per-page text, page and word counts, and document metadata.

# 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://arxiv.org/pdf/1706.03762"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("spellzcode/pdf-to-text-extractor").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://arxiv.org/pdf/1706.03762"] }

# Run the Actor and wait for it to finish
run = client.actor("spellzcode/pdf-to-text-extractor").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://arxiv.org/pdf/1706.03762"
  ]
}' |
apify call spellzcode/pdf-to-text-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,spellzcode/pdf-to-text-extractor"
        }
    }
}
```

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/VQYD4jahymczgbdrD/builds/id6aVTRZbkcmvzb8w/openapi.json
