# PDF to Text & OCR – PDF & Image Text Extraction (Erdnal) (`erdnal_api/erdnal-documents-text-extraction`) Actor

PDF to text and OCR: extract text from PDFs, scanned PDFs and JPEG/PNG images (image to text) by URL, page by page, as JSON, text or Markdown. Optional invoice to JSON. EU-hosted, documents not kept. Pay per page.

- **URL**: https://apify.com/erdnal_api/erdnal-documents-text-extraction.md
- **Developed by:** [Erdnal](https://apify.com/erdnal_api) (community)
- **Categories:** AI, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.40 / 1,000 page credits

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 to Text & OCR – PDF & Image Text Extraction (Erdnal Documents)

Extract the text of PDF files and JPEG/PNG images from their URLs. Text-based PDFs are read directly from their
text layer (fast and exact); scanned pages and images go through OCR (Tesseract). You get the full text and the
text of each page, with an OCR confidence score. You pay only for documents that were extracted successfully.

### What it does

- **Input:** public URLs of PDF, JPEG or PNG files, up to 500 per run (for example links collected by a scraper,
  or an export of invoices, reports or forms).
- **Smart mode:** in `auto` mode, each PDF page is read from its text layer when it has one, and only pages
  without usable text (scans) are sent to OCR. That is cheaper and more accurate than OCR on every page.
- **OCR languages:** English, French, German, Spanish, Italian, Portuguese, Dutch (up to 3 per run).
- **Output:** one dataset row per document with the full text, the number of pages, how many needed OCR, the
  lowest OCR confidence and, optionally, the text of each page.
- **Privacy:** documents are processed by the Erdnal Documents API, hosted in the European Union, only to produce
  the result. Erdnal does not keep the documents or the extracted text after the response.
- **Safe input handling:** the real file type is checked, each document is processed in an isolated,
  resource-limited process, and password-protected PDFs are refused.

Example: the sample invoice (2 pages: one with a text layer, one scanned) gives the invoice lines from page 1
without OCR, and the payment terms from page 2 by OCR.

### Invoice & Receipt to JSON

Set **What to extract** (`extract`) to **Invoice data** to turn invoices and receipts (PDF, scan or photo) into
accounting data instead of text. Each dataset row then has an `invoice` object:

```json
{
  "document_type": "invoice",
  "invoice_number": "INV-2026-0042",
  "invoice_date": "2026-11-01",
  "supplier_name": "Demo Supplier Ltd",
  "customer_name": "Fictitious Customer",
  "currency": "EUR",
  "total": 324.0,
  "tax_lines": [],
  "line_items": [{"description": "Web hosting, 12 months", "quantity": 1, "unit_price": null, "amount": 180.0}]
}
```

All fields: document type, number, invoice and due dates, supplier name, VAT number and address, customer name and
VAT number, currency, subtotal, tax total, tax lines, total and line items. Missing fields are `null`. The text is
read from the PDF text layer or by OCR, then structured by an AI model (Anthropic): **in this mode only, the
extracted text is sent to Anthropic**; nothing is stored. Cost: the text extraction **plus 5 credits per page**
(first 5 pages by default).

### Use cases

- **Document pipelines:** turn PDF reports, invoices or forms into text for search, indexing or an LLM.
- **Scanned archives:** OCR scanned PDFs and photos of documents to make them searchable.
- **Scraping workflows:** chain it after a scraper that collects PDF links.
- **RAG and AI agents:** get clean page-by-page text before chunking and embedding.

### How to use

1. Paste the document URLs into **Document URLs** (one per line).
2. Keep **Extraction mode** on `auto`, and choose the OCR languages of your documents.
3. Click **Start**. When the run ends, open the **Output** tab.

Input example:

```json
{
  "documentUrls": ["https://api.erdnal.com/v1/documents/samples/demo-invoice.pdf"],
  "mode": "auto",
  "languages": ["eng"],
  "pages": "1-5"
}
```

| Field | Description | Default |
|---|---|---|
| `documentUrls` | Public `https://` URLs of PDF, JPEG or PNG files (1 to 500) | — |
| `mode` | `auto` (text layer, OCR for scanned pages), `text` (never OCR), `ocr` (OCR every page) | `auto` |
| `languages` | 1 to 3 of `eng`, `fra`, `deu`, `spa`, `ita`, `por`, `nld` | `eng`, `fra` |
| `pages` | Pages to extract, e.g. `1-3,7` | all pages |
| `includePages` | Add the text and details of each page | on |

### Output example

```json
{
  "index": 0,
  "documentUrl": "https://api.erdnal.com/v1/documents/samples/demo-invoice.pdf",
  "ok": true,
  "inputType": "pdf",
  "pagesTotal": 2,
  "pagesProcessed": 2,
  "ocrPages": 1,
  "text": "INVOICE INV-2026-0042 (SAMPLE)\nDemo Supplier Ltd, ...\n\nPAYMENT TERMS (scanned page)\n...",
  "chars": 496,
  "minConfidence": 0.962,
  "pages": [
    {"page": 1, "method": "text", "text": "INVOICE INV-2026-0042 (SAMPLE) ...", "chars": 305, "confidence": null},
    {"page": 2, "method": "ocr", "text": "PAYMENT TERMS (scanned page) ...", "chars": 191, "confidence": 0.962}
  ],
  "creditsCharged": 5,
  "errorCode": null
}
```

A failed document has `ok: false`, `creditsCharged: 0` and an `errorCode`, and the run goes on with the next one.

### Pricing

Pay per event: **$0.0005 per credit**. Apify Store discounts apply to paid Apify plans: 10 % off on Bronze, 15 % on Silver, 20 % on Gold and above.

| Page | Credits | Price |
|---|---|---|
| Page read from the PDF text layer | 1 | $0.0005 |
| Page read by OCR (scanned PDF page, image) | 4 | $0.002 |
| Invoice data (`extract: invoice`), per page, on top of the text | +5 | +$0.0025 |

A tiny start fee ($0.00005) is charged per run. **Failed documents are free** (unreachable URL, unsupported or
password-protected file, too many pages). The Actor respects your maximum cost per run: each document is refused
before OCR if it would cost more than your remaining budget.

### Limits

- 20 MB per file, 200 pages per document (use `pages` for longer documents);
- 5 OCR pages per document: for a longer scanned PDF, split it with `pages` (`1-5`, `6-10`, …) in several URLs
  or runs;
- OCR takes about 3 to 4 seconds per page.

### FAQ

**Is this OCR good enough for my documents?**
It works well on text PDFs, clean scans (also small fonts, two columns, slightly skewed pages) and gridded
tables. It is weaker on photos of documents taken with a phone (perspective, shadows) and does not read
handwriting. Check `minConfidence`: below about 0.8, review the text.

**Does it extract invoice fields?**
Yes: set `extract` to `invoice` (see above). A one-page invoice costs about $0.003 to $0.0045 (text or OCR plus
the invoice data). Generic tables are returned as text in reading order.

**Why did a document fail?**
Each failed document has an `errorCode`:

- `document_url_unreachable` / `document_url_timeout`: the host could not be reached or returned an error;
- `document_url_forbidden`: only public `https://` URLs on port 443 are accepted;
- `document_url_redirect`: more than 3 redirects;
- `unsupported_format`: not a PDF, JPEG or PNG file;
- `pdf_encrypted`: password-protected PDF;
- `too_many_pages` / `too_many_ocr_pages`: use `pages` to extract a smaller range;
- `max_credits_exceeded`: the document costs more than your remaining budget for this run;
- `file_too_large` / `image_too_large`: 20 MB per file, 25 megapixels per image.

### Use it from AI agents (MCP)

AI agents can run this Actor through the Apify MCP server (Claude, Cursor, VS Code, GitHub Copilot, Codex). Add this server URL to your MCP client and sign in with your Apify account when asked:

```
https://mcp.apify.com?tools=erdnal_api/erdnal-documents-text-extraction
```

The agent sees the input and output schemas, runs the Actor and reads the results; runs are billed per event, like a normal run.

### Integrations

- **API:** start runs and read results with the Apify API or the Apify clients for JavaScript and Python.
- **Make, Zapier, n8n:** run the Actor from these tools and send the text to a database, a spreadsheet or an AI
  step.
- **Webhooks:** call your own endpoint when a run finishes.

### More from Erdnal

- [Image Compression & WebP AVIF Converter](https://apify.com/erdnal_api/erdnal-media-image-optimizer): compress images and convert JPG/PNG to WebP or AVIF in bulk, with resizing and metadata removal.
- [Invoice & Receipt to JSON](https://apify.com/erdnal_api/erdnal-documents-text-extraction/examples/invoice-to-json): a ready-made task of this Actor for invoice data.

### Support

support@erdnal.com — include the `requestId` of the document concerned.

# Actor input Schema

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

Public https:// URLs of the PDF, JPEG or PNG files to read, one per line (1 to 500 per run, 20 MB per file, up to 3 redirects, e.g. download links). Each file becomes one row of the output.

## `extract` (type: `string`):

Text (default): the text of every page, read from the PDF text layer or by OCR for scans. Invoice data: invoice or receipt fields as JSON (number, dates, supplier and VAT number, customer, currency, subtotal, tax lines, total, line items); costs 5 extra credits per page and sends the extracted text to an AI model (Anthropic).

## `mode` (type: `string`):

Auto (default, cheapest and most accurate): pages with a text layer are read directly, only scanned pages go through OCR. Text: never use OCR (scanned pages come back empty). OCR: run OCR on every page, even when a text layer exists (useful if the text layer is broken).

## `languages` (type: `array`):

Languages of your documents, used by OCR only (1 to 3). Choose only the languages actually present: each extra language makes OCR slower. Default English and French.

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

Pages to extract, e.g. 1-3,7 (numbers start at 1). Leave empty for all pages (200 at most). A document can have at most 5 pages read by OCR per run: split long scanned documents with page ranges.

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

On (default): add the text, method (text layer or OCR) and OCR confidence of each page, besides the full text. Off: only the full text, for smaller output.

## Actor input object example

```json
{
  "documentUrls": [
    "https://api.erdnal.com/v1/documents/samples/demo-invoice.pdf"
  ],
  "extract": "text",
  "mode": "auto",
  "languages": [
    "eng",
    "fra"
  ],
  "includePages": true
}
```

# Actor output Schema

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

Dataset items, overview view: source URL, pages, OCR pages, characters, confidence, credits, error code, text.

# 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 = {
    "documentUrls": [
        "https://api.erdnal.com/v1/documents/samples/demo-invoice.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("erdnal_api/erdnal-documents-text-extraction").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 = { "documentUrls": ["https://api.erdnal.com/v1/documents/samples/demo-invoice.pdf"] }

# Run the Actor and wait for it to finish
run = client.actor("erdnal_api/erdnal-documents-text-extraction").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 '{
  "documentUrls": [
    "https://api.erdnal.com/v1/documents/samples/demo-invoice.pdf"
  ]
}' |
apify call erdnal_api/erdnal-documents-text-extraction --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,erdnal_api/erdnal-documents-text-extraction"
        }
    }
}
```

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/WCRHNtzBTkYdC7zXq/builds/kbAuYtz5OGDLdfjZZ/openapi.json
