# Document OCR & PDF Text API (`soilair/document-ocr-api`) Actor

Extract text from public PDFs and images using native PDF text when available and local Tesseract OCR fallback.

- **URL**: https://apify.com/soilair/document-ocr-api.md
- **Developed by:** [Salih Can Kurnaz](https://apify.com/soilair) (community)
- **Categories:** Business, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.60 / 1,000 ocr page results

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?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Document OCR & PDF Text API

Extract text from public PDF and image URLs with a hybrid pipeline optimized for both quality and cost.

For PDFs, the Actor first checks each page for a usable embedded text layer. If the page already contains real text, the Actor extracts it directly with Poppler `pdftotext`. If usable text is not available, the page is rendered and processed with local Tesseract OCR. Raster image inputs always use Tesseract OCR.

This avoids wasting OCR compute on text-native PDFs while preserving OCR fallback for scanned PDFs and images.

### Input

Provide one or more public `http://` or `https://` URLs in `documentUrls`.

Use:

- `maxPagesPerDocument` to bound PDF pages,
- `maxResults` to bound total emitted page rows,
- `maxDownloadMb` to cap each source download,
- `language` for the installed OCR language,
- `skipInvalidUrls` to continue after blocked or invalid sources.

### Security

The Actor is intended only for public internet documents. It blocks URL credentials, localhost, loopback, private, link-local, reserved/non-global IP addresses, and common metadata hostnames. Redirect targets are validated again before they are followed. Downloads are byte-limited.

### Output

Each Dataset row represents one page or image and includes `extractionMethod`:

- `pdf-text` — usable text was extracted directly from the PDF page.
- `tesseract-ocr` — raster OCR was required.

The Actor never emits packaged benchmark fixtures in customer runs. Only user-provided source URLs create Dataset rows.

### OCR behavior

Tesseract is strongest on clear machine-printed text. Handwriting, poor scans, perspective distortion, unusual scripts, complex forms, and heavy compression can reduce accuracy.

The Actor does not claim universal OCR accuracy. High-impact legal, medical, financial, compliance, or identity use should independently verify extracted text.

### Billing

The primary pay-per-event event is `page-result`. One result event corresponds to one page or image successfully written to the Dataset. Billing verification uses the event-specific charging counter.

### Example

```json
{
  "documentUrls": [
    "https://www.irs.gov/pub/irs-pdf/fw9.pdf"
  ],
  "maxPagesPerDocument": 6,
  "maxResults": 20,
  "maxDownloadMb": 30,
  "language": "eng",
  "skipInvalidUrls": true
}
```

# Actor input Schema

## `documentUrls` (type: `array`):

Public HTTP(S) PDF or image URLs to OCR.

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

Maximum PDF pages processed from each document.

## `maxResults` (type: `integer`):

Maximum OCR page rows emitted across the entire run.

## `maxDownloadMb` (type: `integer`):

Maximum downloaded bytes per source document.

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

Installed Tesseract language. V84 production candidate validates English.

## `skipInvalidUrls` (type: `boolean`):

Continue with other documents when a URL is blocked or invalid.

## Actor input object example

```json
{
  "documentUrls": [
    "https://www.irs.gov/pub/irs-pdf/fw9.pdf"
  ],
  "maxPagesPerDocument": 10,
  "maxResults": 50,
  "maxDownloadMb": 30,
  "language": "eng",
  "skipInvalidUrls": true
}
```

# Actor output Schema

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

Default Dataset containing OCR page rows.

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

Structured run metrics, errors and billing counts.

## `report` (type: `string`):

Human-readable run report.

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("soilair/document-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 = {}

# Run the Actor and wait for it to finish
run = client.actor("soilair/document-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 '{}' |
apify call soilair/document-ocr-api --silent --output-dataset

```

## MCP server setup

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