# PDF OCR API - Scanned PDF to Text and Word Boxes (`stas_k/pdf-ocr-api`) Actor

Most PDF OCR actors bill the whole document even when a page carries no text. This one charges per delivered page only: the embedded text layer is used where it exists, Tesseract reads the scans in English, Russian and Ukrainian, and word boxes come with confidence.

- **URL**: https://apify.com/stas_k/pdf-ocr-api.md
- **Developed by:** [Stas K](https://apify.com/stas_k) (community)
- **Categories:** AI, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

$6.00 / 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.

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 OCR API: scanned PDF to text, charged per page

Give it a list of pdf urls. It reads the pages you ask for (10 per document by
default, `maxPagesPerDocument` changes that, 0 means all of them) and writes one row per
page: the text, where that text came from, and how confident the recogniser was. Pages
past the limit are not read and not charged, and `pagesCutByLimit` says how many were
left, so a cut document is visible instead of looking complete.

No API key is needed on either side. The recognition runs inside the image with
Tesseract, so a scanned contract is read on our machine and your document never goes
to a third party service.

### What you get

One dataset row per page:

- `text`: the page as plain text, lines rebuilt in reading order rather than one long
  run of words.
- `source`: `text` when the page carried its own text layer (exact, instant, free of
  recognition error) or `ocr` when Tesseract read a scan.
- `confidence`: mean word confidence for an OCR page, `null` for a text layer because
  there is nothing estimated there.
- `words`: every word with its box and confidence, when `includeWords` is on. This is
  what a form parser or a redaction tool needs.
- `page`, `pagesInDocument`, `pagesLeft`: where you are in the document, and how much of
  it this run did not cover.

### What it costs

`$6.00 per 1,000 pages`, charged per page that carried text.

A page with nothing readable on it is free and comes back as `NOT_CHECKED_NO_TEXT`: a
blank scan, a separator page, or a picture without print. That is the difference from
most actors in this niche, which bill the whole document whether the text came out or
not.

### What it does not do

- It does not guess. A page whose scan was unreadable is marked free with a reason, not
  delivered as an empty string.
- It does not handle a password protected pdf. It says `NOT_CHECKED_ENCRYPTED` and
  charges nothing.
- It does not read handwriting reliably. Tesseract reads print; a handwritten note will
  come back with wrong words and a low confidence, and the confidence is there so you
  can filter those rows yourself.
- It does not keep your file. The pdf is downloaded, read and dropped inside the run.
- It does not translate, summarise or classify. This actor turns pages into text, and
  nothing else.

### Settings that matter

- `ocrMode`: `auto` reads a digital page from its text layer and only sends a scan to
  OCR. `always` forces recognition, for a pdf whose text layer is garbled. `never` never
  pays for recognition, and a scan then comes back free with `NOT_CHECKED_NO_TEXT`.
- `pages`: a range like `1-5,9`. Pages outside the document are counted in the summary
  as `pagesNotInDocument`, never silently dropped. A range that names only pages this
  document does not have comes back as `NOT_CHECKED_NO_SUCH_PAGE`, not as a bad url.
- `maxPagesPerDocument`: how far into one document this run goes. What is left is
  counted in `pagesCutByLimit`.
- `dpi`: 200 reads ordinary 10 to 12 point print. 300 helps with small print and costs
  roughly twice the time.
- `languages`: English, Russian, Ukrainian, and their combinations. A page in a language
  that is not selected comes back with wrong words rather than with an error.

### Honest numbers

Recognition time depends on the page, not on a promise: a plain text page at 200 dpi
takes about one to two seconds on one core, a dense scan with small print can take four
or five. The actor watches the platform deadline and stops before it, and the time left
caps the recognition itself, so a page that cannot finish in time comes back as a free
`NOT_CHECKED_TIME` or `NOT_CHECKED_ERROR` row instead of the run being killed mid file.

Accuracy is a property of the scan, not of this actor: a clean 300 dpi scan of printed
text usually comes back word perfect, a photo of a page at an angle does not. The
`confidence` field is there because a single number is more useful than a claim.

### Refusals

Every refusal is a row of its own, free, with the reason in plain words:

| status | meaning |
| --- | --- |
| `NOT_CHECKED_INVALID` | the line is not an http url |
| `NOT_CHECKED_DUPLICATE` | the same url came earlier, the document is read once |
| `NOT_CHECKED_LIMIT` | beyond `maxDocuments` |
| `NOT_CHECKED_PRIVATE_ADDRESS` | a host name really answered with a non public address |
| `NOT_CHECKED_DNS_ERROR` | the host name does not resolve or is not a valid name |
| `NOT_CHECKED_FETCH_ERROR` | the download failed or timed out |
| `NOT_CHECKED_TOO_LARGE` | bigger than 80 MB |
| `NOT_CHECKED_NOT_PDF` | the bytes are not a pdf, whatever the url or content type says |
| `NOT_CHECKED_ENCRYPTED` | the document needs a password |
| `NOT_CHECKED_BROKEN_PDF` | the file could not be parsed |
| `NOT_CHECKED_NO_TEXT` | the page had neither a text layer nor readable print |
| `NOT_CHECKED_NO_SUCH_PAGE` | the `pages` range named only pages this document does not have |
| `NOT_CHECKED_TIME` | the platform deadline was close |
| `NOT_CHECKED_CAP` | the spending cap of the run was reached |
| `NOT_CHECKED_BILLING` | the price could not be read, so nothing was sold |
| `NOT_CHECKED_ERROR` | this page could not be read, or the run stopped before it |

Note what `NOT_CHECKED_NOT_PDF` means: a link that answers with an html login page is
refused before any parser touches it, because a pdf signature is looked for in the
first kilobyte. An html page billed as a document is the classic way a pdf actor takes
money for nothing.

### The run summary

In the key value store, under `RUN_SUMMARY` and under `RUN_SUMMARY-<runId>` in the
`pdf-ocr-api-summary` store:

- `requested`, `uniqueDocuments`, `duplicates`, `invalidLines`, `blankLines`
- `linesThatAreNotDocuments` (a bad url, a repeat, a blank line, a line past
  `maxDocuments`) and `documentsAttempted`: the lines that really were documents
- `processedDocuments`, `documentsAttempted` and `notCheckedDocuments`: processed counts
  a document that was opened and read, even when every page of it had no text, and a
  document we never reached is not checked, so the two add up to `documentsAttempted`
  and `linesThatAreNotDocuments` closes the count back to `requested`
- `deliveredPages` and `chargedEvents`: the second one is the money actually taken, so
  when the two differ, trust it and read `deliveredUncharged`
- `pagesFromTextLayer` and `pagesFromOcr`: how much of the work was real recognition
- `pagesWithoutText`, `pagesCutByLimit`, `pagesNotInDocument`, `ocrSeconds`
  `stopReason` names why the run stopped early, if it did.

# Actor input Schema

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

One pdf url per line. Each document is read once: the embedded text layer is used where a page has one, and the scans are recognised with Tesseract. A line that is not an http url, a repeat of an earlier line and a line beyond maxDocuments come back as their own free row with the reason.

## `maxDocuments` (type: `integer`):

The list is cut here and the rest comes back free with status NOT_CHECKED_LIMIT. 0 means the default of 10, and the summary reports the number actually applied.

## `maxPagesPerDocument` (type: `integer`):

Pages beyond this are not read and not charged, and the row of the last read page says how many were left. 0 means every page.

## `pages` (type: `string`):

A page range like 1-5,9 for every document, or leave it empty to read from the first page. Numbering starts at 1, and a range that does not fit the document is reported in the summary.

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

Language packs that ship inside the image. More languages slow the recognition down, and a page in a language that is not in the list comes back with wrong words rather than with an error.

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

auto is what a mixed document needs: a digital page is read exactly and instantly, and only a scanned page goes through OCR. always is for a scan wrapped in a pdf with a broken text layer. never never pays for OCR time.

## `dpi` (type: `integer`):

How large a scanned page is rendered before recognition. 200 reads ordinary 10 to 12 point print; 300 helps with small print and costs roughly twice the time; below 150 small print starts to fail.

## `includeWords` (type: `boolean`):

Adds every recognised word with its box and confidence, which is what a form parser or a redaction tool needs. It makes each row several times larger, so it is off by default.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "maxDocuments": 10,
  "maxPagesPerDocument": 10,
  "pages": "",
  "languages": "eng",
  "ocrMode": "auto",
  "dpi": 200,
  "includeWords": false
}
```

# Actor output Schema

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

One row per page. status is OK when the row carries text, or NOT_CHECKED\_\* with the reason in plain words: INVALID (the line is not an http url), DUPLICATE (the same url came earlier), LIMIT (beyond maxDocuments), PRIVATE_ADDRESS (a host name really answered with a non public address, whether the document host or a redirect hop), DNS_ERROR (the host name does not resolve or is not a valid host name), FETCH_ERROR (the document could not be downloaded), TOO_LARGE (bigger than 80 MB), NOT_PDF (the bytes are not a pdf, whatever the url says), ENCRYPTED (a password is needed), BROKEN_PDF (the file could not be parsed), NO_TEXT (the page has neither a text layer nor readable print, so it is free), NO_SUCH_PAGE (the pages field named only pages this document does not have), TIME, CAP, BILLING and ERROR (the run stopped before this page for the reason in the summary). source says where the text came from: text for the embedded layer, which is exact and instant, or ocr for Tesseract. chars is the length of that page's text and confidence is the mean word confidence of an OCR page, null for a text layer because it is not an estimate. words is filled only when includeWords is on. pagesInDocument, pageCountRead and pagesLeft say how much of the document this run covered, so a cut document is visible on its own rows. billable is true only on a row that carries text; the money actually taken is in the run summary.

## `summary` (type: `string`):

Run summary. requested is how many lines were sent, unique is how many different documents were read, linesThatAreNotDocuments counts the lines that never were a document (a bad url, a repeat, a blank line, a line past maxDocuments) and documentsAttempted is the rest, the lines that really were documents. processed counts a document that was opened and read, even when every page of it carried no text, and notChecked counts a document this run never reached, so processed plus notChecked always equals documentsAttempted and documentsAttempted plus linesThatAreNotDocuments always equals requested. deliveredPages is how many pages were written with text and chargedEvents is how much money was really taken, which is the number to trust when the two differ. pagesWithoutText counts free pages that had nothing to read, pagesCutByLimit counts pages left unread because of maxPagesPerDocument, and pagesNotInDocument counts page numbers from the pages field that the document does not have. billingActive and billingReason say whether this run could charge at all; a run with billing off still delivers rows and reports chargedEvents 0. stopReason names the reason the run stopped early, if it did, and deliveredUncharged counts rows that may be in the dataset without money taken. datasetItemCount is what this run wrote, datasetItemCountApi is what the platform reports and it lags by minutes, so a smaller number there is a lag and not a lost row. The same summary is in the summary store under RUN_SUMMARY-<runId>.

# 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("stas_k/pdf-ocr-api").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("stas_k/pdf-ocr-api").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 stas_k/pdf-ocr-api --silent --output-dataset

```

## MCP server setup

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

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/SrAdAu7MubP7i0X6o/builds/gDb9EuDumR1W2beBW/openapi.json
