# Document to Markdown for RAG: PDF, Word, Excel (`nemata/document-to-markdown`) Actor

Turn PDFs, scans (OCR), Word, PowerPoint, Excel, OpenDocument, EPUB and web pages into clean Markdown, text, tables and heading-aware RAG chunks for LLMs, vector databases and AI agents. Pay per page.

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

## Pricing

from $2.00 / 1,000 page processeds

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 for RAG: PDF, Word, PowerPoint, Excel, HTML, EPUB + OCR

Turn almost any document link into **clean Markdown, plain text, tables and ready-to-embed chunks** for RAG pipelines, LLM prompts, AI agents, search indexes or spreadsheets.

- **15+ formats, one output.** PDF, scans and images (OCR), Word (DOCX), PowerPoint (PPTX, with speaker notes), Excel (XLSX), OpenDocument (ODT, ODP, ODS), EPUB e-books, HTML web pages, RTF, TXT, Markdown, CSV and JSON.
- **Real structure, not a wall of text.** Headings, nested lists, links and tables are kept as Markdown, so an LLM sees the document the way a person does.
- **RAG chunks built in.** Heading-aware chunks with a size and overlap you choose. Tables are split by rows and keep their header row. Each chunk carries its heading path (`Handbook > Holidays > Public holidays`) and a `textWithContext` field ready for embeddings.
- **Automatic OCR for scanned pages** in 9 languages: English, Spanish, French, German, Italian, Portuguese, Dutch, Catalan, Polish.
- **Web pages without the clutter.** Menus, headers, footers, scripts and forms are removed. robots.txt is respected.
- **Pay only for what you process.** No subscription.

### Use cases

- Feed contracts, reports, manuals, slide decks or spreadsheets into a vector database
- Give an AI agent the ability to "read" any document link
- Make scanned archives searchable
- Pull tables out of PDFs and spreadsheets as rows

### Input

| Field | Description |
|---|---|
| `files` | Direct links to documents (any format above). Up to 100 MB each. The type is detected from the content, so links without an extension work too. |
| `outputMode` | `file` (default): one item per document. `page`: one item per page, slide, sheet or chapter. `chunks`: RAG chunks. |
| `chunkSize` / `chunkOverlap` | Chunk size and overlap in characters (default 2,000 / 200). About 4 characters = 1 token. |
| `includeSlideNotes` | Add PowerPoint speaker notes under each slide (default: on). |
| `ocrMode` | PDFs and images. `auto` (default): OCR only pages without text. `always`: OCR every page. `never`: no OCR. |
| `ocrLanguages` | Languages in scanned documents. Default: English. |
| `extractTables` / `tableMode` | PDF table detection: `lines` (ruled tables, default) or `text` (borderless tables). |
| `maxPagesPerFile` | Process only the first N pages, slides, sheets or chapters. |

Example:

```json
{
  "files": [
    { "url": "https://example.com/handbook.docx" },
    { "url": "https://example.com/report.pdf" }
  ],
  "outputMode": "chunks",
  "chunkSize": 1500,
  "chunkOverlap": 150
}
```

### Output

With `outputMode: "file"`:

```json
{
  "url": "https://example.com/handbook.docx",
  "type": "docx",
  "metadata": { "title": "Handbook", "creator": "HR" },
  "billedPages": 4,
  "text": "Employee Handbook\n\n1. Holidays\n...",
  "markdown": "# Employee Handbook\n\n# 1. Holidays\n\nEveryone gets 25 days...\n\n- Ask your manager first\n- Book in the HR tool\n\n| Type | Days |\n| --- | --- |\n| Paid | 25 |",
  "tables": [[["Type", "Days"], ["Paid", "25"]]]
}
```

With `outputMode: "chunks"`, one item per chunk:

```json
{
  "url": "https://example.com/handbook.docx",
  "type": "docx",
  "chunkIndex": 3,
  "page": 1,
  "headings": ["Employee Handbook", "1. Holidays", "1.1 Public holidays"],
  "text": "Madrid public holidays apply. ...",
  "textWithContext": "Employee Handbook > 1. Holidays > 1.1 Public holidays\n\nMadrid public holidays apply. ...",
  "chars": 1412
}
```

Slides come with `slide`, spreadsheets with `sheet` and e-books with `chapter` instead of `page`. Files that cannot be read return an item with an `error` field; the rest of the run continues.

### Use with AI agents

- **MCP:** AI assistants and agents can call this Actor as a tool through the Apify MCP server.
- **No Apify account needed for agents:** agents can pay per run through Apify with x402 (stablecoins) or Skyfire, and then call the Actor with the temporary token they receive.
- Clear JSON input and structured JSON output that an agent can use directly.

### Pricing

**$0.002 per page** ($2 per 1,000). The price is the same for every Apify plan you are on, and you can set a maximum cost per run in the run options.

Pay per event: you are charged **per page processed**. For PDFs and images a page is a real page. For slides, one slide = one page. For formats without pages (Word, Excel, HTML, EPUB, text), one page = 3,000 characters of extracted text, rounded up; a short document is one page. The price is shown on this page. Set a maximum cost per run in the run options and the Actor stops when it is reached.

### Privacy

Files are downloaded only to process them during the run. The Actor does not keep copies; results are stored only in your own Apify dataset.

### Limitations

- OCR quality depends on scan quality. Very low-resolution or handwritten documents give weaker results.
- Password-protected or encrypted files are not supported. Old binary formats (.doc, .ppt, .xls) are not supported: save them as DOCX, PPTX or XLSX.
- Images inside Word, PowerPoint and EPUB files are not OCR'd; only their alt text is kept.
- Web pages that need JavaScript to show their content return little or no text.
- Borderless table detection is heuristic; check results on complex layouts.

# Actor input Schema

## `files` (type: `array`):

Direct links to documents: PDF, images (PNG, JPG, TIFF, WEBP...), Word (DOCX), PowerPoint (PPTX), Excel (XLSX), OpenDocument (ODT, ODP, ODS), EPUB, HTML pages, RTF, TXT, Markdown, CSV or JSON. Up to 100 MB each.

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

'auto' runs OCR only on pages without a text layer (scans). 'always' forces OCR on every page. 'never' skips OCR.

## `ocrLanguages` (type: `array`):

Languages present in the documents. More languages = slower OCR.

## `extractTables` (type: `boolean`):

Detect tables in PDFs and return them as rows and Markdown tables.

## `tableMode` (type: `string`):

'Ruled' finds tables drawn with lines (most reliable). 'Borderless' also finds tables made of aligned columns without lines, but may pick up some surrounding text.

## `outputMode` (type: `string`):

'One per file': the whole document in one item. 'One per page': one item per page, slide, sheet or chapter. 'RAG chunks': heading-aware chunks ready for embeddings, each with its heading path.

## `chunkSize` (type: `integer`):

Target maximum size of each chunk when Output is 'RAG chunks'. About 4 characters = 1 token.

## `chunkOverlap` (type: `integer`):

Characters repeated from the end of the previous chunk in the same section, so ideas cut at a boundary are not lost.

## `includeSlideNotes` (type: `boolean`):

Add PowerPoint speaker notes under each slide.

## `outputPerPage` (type: `boolean`):

Legacy option, same as Output = 'One per page'.

## `maxPagesPerFile` (type: `integer`):

Process only the first N pages (or slides, sheets, chapters) of each file. Leave empty for all.

## Actor input object example

```json
{
  "files": [
    {
      "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    }
  ],
  "ocrMode": "auto",
  "ocrLanguages": [
    "english"
  ],
  "extractTables": true,
  "tableMode": "lines",
  "outputMode": "file",
  "chunkSize": 2000,
  "chunkOverlap": 200,
  "includeSlideNotes": true,
  "outputPerPage": false
}
```

# Actor output Schema

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

No description

# 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 = {
    "files": [
        {
            "url": "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("nemata/document-to-markdown").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 = { "files": [{ "url": "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("nemata/document-to-markdown").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 '{
  "files": [
    {
      "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    }
  ]
}' |
apify call nemata/document-to-markdown --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,nemata/document-to-markdown"
        }
    }
}
```

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/8W8AYRv9muSmuPaml/builds/81iW6p9chklnRNBhg/openapi.json
