# Document to Markdown, OCR & Invoice Extraction (`halrohm/document-to-markdown-ocr`) Actor

Convert PDF, Word, PowerPoint, Excel and HTML files to clean Markdown for LLMs and RAG, OCR images and scanned PDFs, or extract invoice, receipt and form data to your own JSON Schema. Pay per page.

- **URL**: https://apify.com/halrohm/document-to-markdown-ocr.md
- **Developed by:** [arden lynch](https://apify.com/halrohm) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 page converted to markdowns

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

## Document to Markdown, OCR & Invoice Extraction

Turn PDFs, Word, PowerPoint, Excel and HTML files into **clean Markdown for LLMs and RAG**, read text from **images and scanned PDFs**, or pull **invoice, receipt and form data into JSON that matches your own schema**. Paste file URLs, pick a mode, get one dataset row per file.

### What it does

| Mode | Input | Output |
|---|---|---|
| **Document to Markdown** | PDF, DOCX, PPTX, XLSX, XLS, HTML (up to 50 pages) | Markdown with headings, lists and tables kept. Scanned PDF pages are OCR'd automatically. Optionally the full document structure as JSON. |
| **OCR** | PNG, JPG, TIFF, BMP, GIF, WebP, PDF | Plain text, overall and per page (English) |
| **Extract data to JSON** | Image or PDF up to 5 pages, plus your JSON Schema | JSON that fills your schema: vendor, totals, dates, line items, names, anything you define |

Typical speed: Office and HTML files ~0.4 s, PDFs ~4 s per page, OCR ~0.5 s per image, extraction ~4 s per document. Files up to 20 MB.

### Why use it

- **Built for LLM pipelines**: Markdown keeps document structure (headings, tables), so chunking and retrieval work better than with raw text.
- **No templates for extraction**: describe the fields you want as a JSON Schema and the vision model fills them, for any invoice or receipt layout.
- **Private**: files are processed in memory on dedicated servers and deleted as soon as the job ends. Nothing is stored or used for training.
- **Pay only for results**: failed files are never charged.

### Input example

```json
{
  "mode": "extract",
  "fileUrls": ["https://example.com/invoices/inv-1042.pdf"],
  "schema": {
    "type": "object",
    "properties": {
      "vendor": {"type": "string"},
      "invoice_number": {"type": "string"},
      "date": {"type": "string", "description": "YYYY-MM-DD"},
      "total": {"type": "number"},
      "line_items": {"type": "array", "items": {"type": "object", "properties": {
        "description": {"type": "string"}, "amount": {"type": "number"}}}}
    }
  }
}
```

### Output example

Markdown mode:

```json
{
  "url": "https://example.com/report.pdf",
  "fileName": "report.pdf",
  "status": "ok",
  "pages": 5,
  "format": "pdf",
  "markdown": "## Operations Report\n\n| Region | Revenue |\n|---|---|\n| West | $1.2M |",
  "seconds": 14.5
}
```

Extract mode:

```json
{
  "url": "https://example.com/receipt.png",
  "fileName": "receipt.png",
  "status": "ok",
  "pages": 1,
  "data": {"vendor": "Bluefield Logistics", "total": 285.94},
  "seconds": 2.1
}
```

A file that can't be processed gets `"status": "failed"` and an `error` explaining why (for example an unsupported file type or a download error), and isn't charged.

### Pricing

Pay per result:

- **Document to Markdown**: per page (a Word, PowerPoint, Excel or HTML file counts as one page)
- **OCR**: per page
- **Extract**: per document

See the Pricing tab for current prices. Set a maximum cost per run in the run options and the Actor stops before going over it.

### Tips

- URLs must be reachable without logging in (public links or signed URLs from S3, Google Cloud Storage, Dropbox and similar).
- The file type comes from the URL's extension, or the server's Content-Type if there isn't one.
- For extraction, descriptive field names and `description`s ("YYYY-MM-DD", "amount without currency symbol") improve results.
- Use it from your own code through the Apify API, or chain it after a crawler that collects document links.

### Limits

20 MB per file. Markdown: 50 pages per PDF. Extraction: images or PDFs of up to 5 pages. OCR is English. Results can contain errors: check extracted values before relying on them for financial or legal decisions.

# Actor input Schema

## `fileUrls` (type: `array`):

Public or signed URLs of the files to process (max 20 MB each). Markdown: PDF, DOCX, PPTX, XLSX, XLS, HTML. OCR and extraction: PNG, JPG, TIFF, BMP, GIF, WebP or PDF.

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

Markdown: document to clean Markdown with headings and tables (scanned PDFs are OCR'd automatically). OCR: plain text from images and scans. Extract: JSON that fills your schema, for invoices, receipts, forms and résumés.

## `includeStructure` (type: `boolean`):

Also return the full document structure as JSON (headings, paragraphs, tables, page positions). PDFs only.

## `schema` (type: `object`):

A JSON Schema with "type": "object" and "properties". Field names and descriptions guide the extraction. Images or PDFs of up to 5 pages.

## `instructions` (type: `string`):

Optional hints for the extraction, for example "Amounts without currency symbols".

## `maxConcurrency` (type: `integer`):

How many files to process at the same time.

## Actor input object example

```json
{
  "fileUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "mode": "markdown",
  "includeStructure": false,
  "schema": {
    "type": "object",
    "properties": {
      "vendor": {
        "type": "string"
      },
      "invoice_number": {
        "type": "string"
      },
      "date": {
        "type": "string",
        "description": "YYYY-MM-DD"
      },
      "total": {
        "type": "number"
      },
      "currency": {
        "type": "string"
      }
    }
  },
  "maxConcurrency": 3
}
```

# Actor output Schema

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

All results as dataset items (JSON, CSV, Excel and more via the dataset API).

# 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 = {
    "fileUrls": [
        "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    ],
    "schema": {
        "type": "object",
        "properties": {
            "vendor": {
                "type": "string"
            },
            "invoice_number": {
                "type": "string"
            },
            "date": {
                "type": "string",
                "description": "YYYY-MM-DD"
            },
            "total": {
                "type": "number"
            },
            "currency": {
                "type": "string"
            }
        }
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("halrohm/document-to-markdown-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 = {
    "fileUrls": ["https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"],
    "schema": {
        "type": "object",
        "properties": {
            "vendor": { "type": "string" },
            "invoice_number": { "type": "string" },
            "date": {
                "type": "string",
                "description": "YYYY-MM-DD",
            },
            "total": { "type": "number" },
            "currency": { "type": "string" },
        },
    },
}

# Run the Actor and wait for it to finish
run = client.actor("halrohm/document-to-markdown-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 '{
  "fileUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "schema": {
    "type": "object",
    "properties": {
      "vendor": {
        "type": "string"
      },
      "invoice_number": {
        "type": "string"
      },
      "date": {
        "type": "string",
        "description": "YYYY-MM-DD"
      },
      "total": {
        "type": "number"
      },
      "currency": {
        "type": "string"
      }
    }
  }
}' |
apify call halrohm/document-to-markdown-ocr --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,halrohm/document-to-markdown-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/kAhZEVxpr2taztn1q/builds/9hulLXD5ceBQc7R27/openapi.json
