# Document to Markdown for RAG: PDF, Word, Excel, PPT, OCR (`docflow-tools/document-to-markdown-rag`) Actor

Convert PDF, DOCX, XLSX, PPTX and HTML into clean Markdown with real tables, headings and RAG-ready chunks. Scanned PDF pages are read with OCR in 8 European languages. Nothing is stored.

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

## Pricing

from $0.80 / 1,000 page converteds

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

## Document to Markdown for RAG — PDF, Word, Excel, PowerPoint, HTML + OCR

Turn **PDF, DOCX, XLSX, PPTX and HTML** files into **clean Markdown** for LLMs, search and RAG pipelines. You get
headings, real Markdown tables, paragraphs re-joined across line breaks, and **chunks that keep their heading path**.
Scanned PDF pages are read with **OCR (Tesseract)** in 8 European languages, only where needed. Each document is
downloaded into memory, converted and discarded: the file itself is never saved, only the result in your dataset.

### What you get

One dataset item per document URL:

| Field | Description |
|---|---|
| `url` | The document URL you gave |
| `status` | `ok`, or `error` if the file could not be downloaded or converted |
| `error` | Reason of the failure (only when `status` is `error`) |
| `type` | `pdf`, `docx`, `xlsx`, `pptx` or `html`, detected from the file content, not from the URL or extension |
| `pages` | PDF pages converted (always `1` for Word, Excel, PowerPoint and HTML) |
| `ocrPages` | How many of those PDF pages were read with OCR |
| `metadata` | PDF only: `Title`, `Author`, `Subject`, `CreationDate`, `ModDate`, `Producer` (when present) and `totalPages` |
| `perPage` | Optional (`includePerPage`): `[{page, ocr, markdown}]` for each converted PDF page |
| `markdown` | The whole document as Markdown |
| `markdownKey` | Only for very large results (Markdown over 4,000,000 characters): `markdown` is `null` and the full text is saved in the run's key-value store under this key (e.g. `markdown-1`) |
| `chunks` | Optional (`includeChunks`, on by default): `[{index, headings, text, chars}]` |

#### How each format is converted

- **PDF**: headings detected from font size (lines at least 1.25x the body text size, up to 3 heading levels).
  Tables with at least two filled columns become Markdown tables. Words are not glued together and hyphenated line
  breaks are re-joined. Pages with no text layer (fewer than 25 characters) are rendered at 200 DPI and read with OCR.
- **Word (DOCX)**: headings from the `Heading 1-6` / `Title` styles, paragraphs with a list style become `- ` items,
  tables stay in their original position.
- **Excel (XLSX)**: one `## Sheet name` section and one Markdown table per non-empty sheet. Cell values are used,
  not formulas. Up to 5,000 non-empty rows per sheet.
- **PowerPoint (PPTX)**: one `## Slide N: Title` section per slide with bullet points (indented by level), tables
  and speaker notes as `> Notes: ...`.
- **HTML**: headings, lists, links and emphasis are kept; `script`, `style`, `noscript` and `template` are removed
  with their content. The whole page is converted (menus and footers included); there is no JavaScript rendering.

#### How chunks are built

The Markdown is split at every heading. Each chunk carries `headings`, the path of headings above it joined with
`>` (for example `Methods > Data collection`), so the context survives retrieval. A chunk never exceeds
`chunkSize` characters: long sections are cut at a paragraph break, or at a space if there is none nearby.

### Use cases

- Load PDFs, reports, manuals and slide decks into a vector database for RAG.
- Give an AI agent the content of an Office file as Markdown it can read.
- Make scanned PDFs searchable by extracting their text with OCR.
- Turn Excel sheets into Markdown tables that LLMs understand.
- Batch-convert a list of document links into one dataset you can export as JSON, CSV or Excel.

### How to use

1. Open the Actor in Apify Console and click **Try for free** (or **Start**).
2. In **Document URLs**, paste one or more direct links to PDF, DOCX, XLSX, PPTX or HTML files.
3. Optionally limit PDF pages (`1-3,7`), choose the OCR mode and languages, and the chunk size.
4. Click **Start**. When the run finishes, open the **Output** tab or export the dataset.

Input example (field names exactly as the Actor reads them):

```json
{
  "documentUrls": [
    "https://arxiv.org/pdf/1706.03762",
    "https://example.com/files/quarterly-report.docx"
  ],
  "pages": "1-5",
  "ocrMode": "auto",
  "ocrLanguages": ["eng", "spa"],
  "includeChunks": true,
  "chunkSize": 2000,
  "includePerPage": false
}
```

| Input | Default | Notes |
|---|---|---|
| `documentUrls` | (required) | http or https links, up to 50 MB each |
| `pages` | all pages | PDF only, e.g. `1-3,7`. Ignored for other formats |
| `ocrMode` | `auto` | `auto` = OCR only pages without text, `always` = OCR every PDF page, `never` = no OCR |
| `ocrLanguages` | `["spa", "eng"]` | Any of `spa`, `eng`, `fra`, `deu`, `ita`, `por`, `cat`, `nld`. Unknown codes are ignored |
| `includeChunks` | `true` | Return RAG chunks |
| `chunkSize` | `2000` | 200 to 20,000 characters |
| `includePerPage` | `false` | Also return Markdown per PDF page |

### Output example

```json
{
  "url": "https://example.com/files/annual-report.pdf",
  "status": "ok",
  "type": "pdf",
  "pages": 3,
  "ocrPages": 1,
  "metadata": {
    "Title": "Annual Report 2025",
    "Producer": "LibreOffice 7.6",
    "CreationDate": "D:20260115093000+01'00'",
    "totalPages": 42
  },
  "perPage": [],
  "markdown": "# Annual Report 2025\n\n## Summary\n\nRevenue grew in all regions...\n\n| Region | 2024 | 2025 |\n| --- | --- | --- |\n| North | 1.2 | 1.4 |\n",
  "chunks": [
    {
      "index": 1,
      "headings": "Annual Report 2025 > Summary",
      "text": "## Summary\n\nRevenue grew in all regions...",
      "chars": 1874
    }
  ]
}
```

A failed document gets a short item like this, and the other documents keep going:

```json
{ "url": "https://example.com/missing.pdf", "status": "error", "error": "download: Client error '404 Not Found' for url ..." }
```

### Pricing

> **Prices by Apify discount tier:** the prices below are for the Bronze tier. **Free plan: 50 % off.** Silver: 10 % off. Gold and higher: 20 % off. Apify applies the right price automatically.

Pay per event, in USD. Platform compute is included in the event prices.

| Event | Price | When it is charged |
|---|---|---|
| Actor start | $0.00005 | Charged by Apify when a run starts, per GB of run memory (default memory: 2 GB) |
| `document-processed` | $0.003 | Once per document converted successfully |
| `page-converted` | $0.001 | Per PDF page converted from its text layer; one per Word, Excel, PowerPoint or HTML file |
| `ocr-page` | $0.008 | Per PDF page read with OCR (instead of `page-converted`, not in addition) |

Documents that fail to download or convert are **not charged**. Events are charged after the result is saved.

Examples:

- **One 15-page text PDF** (2 GB run, start $0.0001): 0.0001 + 0.003 + 15 x 0.001 = **$0.0181**
- **10 Word files**: 0.0001 + 10 x (0.003 + 0.001) = **$0.0401**
- **One 20-page scanned PDF** (`ocrMode: auto`): 0.0001 + 0.003 + 20 x 0.008 = **$0.1631**

With `ocrMode: always`, every PDF page is charged as `ocr-page`. You can set a maximum cost per run in Apify; when
it is reached, the Actor stops before the next document.

### Use it from code, AI agents and integrations

**Apify API** (runs the Actor and returns the dataset items in one call):

```bash
curl -X POST "https://api.apify.com/v2/acts/docflow-tools~document-to-markdown-rag/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"documentUrls": ["https://arxiv.org/pdf/1706.03762"], "pages": "1-3"}'
```

**Python** (`pip install apify-client`):

```python
from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("docflow-tools/document-to-markdown-rag").call(
    run_input={"documentUrls": ["https://arxiv.org/pdf/1706.03762"], "chunkSize": 1500}
)
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item["status"], item.get("type"), len(item.get("chunks", [])))
```

**AI agents**: the Actor can be called by AI agents (Claude, Cursor and other MCP clients) through the Apify MCP
server at https://mcp.apify.com.

**No-code**: connect it to Make, Zapier or n8n through the Apify integrations, or run it on a schedule or webhook.

### Limits and notes

- Up to **50 MB** per file; only `http://` and `https://` URLs; redirects are followed; download timeout 120 s.
- Up to 2,000 pages per PDF in one run.
- Supported: PDF, DOCX, XLSX, PPTX, HTML. Not supported: legacy `.doc`, `.xls`, `.ppt`, RTF, OpenDocument,
  image files (see Image to Text OCR below), password-protected files.
- Documents are processed one after another, in the order given.
- PDF tables drawn only with horizontal rules (common in academic papers) come out as text, not as a table.
- Excel formulas are returned as their last saved value; a file never calculated by Excel may show empty cells.
- OCR runs only on PDF pages, not on pictures embedded in Word or PowerPoint. OCR quality depends on the scan.
- The Actor does not log in to websites and does not render JavaScript: the URL must return the file itself.

### FAQ

**Does it work with scanned PDFs?** Yes. In `auto` mode each page without a text layer is read with Tesseract OCR
in the languages you choose. Pages with text are not OCR'd, so `ocr-page` is only charged where it is needed.

**Which OCR languages are available?** Spanish (`spa`), English (`eng`), French (`fra`), German (`deu`), Italian
(`ita`), Portuguese (`por`), Catalan (`cat`) and Dutch (`nld`). Choose only the ones in your documents.

**Can I convert only some pages?** Yes, with `pages` (for example `1-3,7`). Only those pages are converted and charged.

**What happens if one URL fails?** You get an item with `status: "error"` and the reason, it is not charged, and
the remaining documents are processed normally.

**Is my document stored?** The file is held in memory only while it is converted. What remains is the output you
asked for (Markdown, chunks, metadata) in your own Apify dataset.

**What if the result is huge?** If the Markdown exceeds 4,000,000 characters, it is saved in the run's key-value
store and the dataset item gives its key in `markdownKey`.

### Related tools

- [RSS, Atom & JSON Feed Reader](https://apify.com/docflow-tools/feed-reader-only-new) — feeds in one format, only new items on scheduled runs.
- [Bulk PageSpeed & Core Web Vitals](https://apify.com/docflow-tools/pagespeed-bulk-regression-monitor) — Google PageSpeed for many URLs with regression alerts.
- [Image to Text OCR](https://apify.com/docflow-tools/image-ocr-own-engine) — text, lines and positions from images.
- [Audio Transcriber (Whisper)](https://apify.com/docflow-tools/audio-transcriber-whisper-local) — audio and video to text and subtitles.
- [Merge, Dedupe & Transform Data](https://apify.com/docflow-tools/merge-dedupe-transform-data) — merge datasets and files, remove duplicates, export.
- [Website Screenshot Monitor](https://apify.com/docflow-tools/website-screenshot-monitor) — bulk screenshots with change detection.
- [Bulk Image Converter & Compressor](https://apify.com/docflow-tools/bulk-image-converter-compressor) — convert, compress and resize images.
- [Sitemap URL Extractor](https://apify.com/docflow-tools/sitemap-url-extractor-reliable) — every URL of a site from its sitemaps.
- [SEO Audit Crawler](https://apify.com/docflow-tools/seo-audit-crawler-cheap) — on-page SEO score and issues per page.
- [Website to Markdown & llms.txt](https://apify.com/docflow-tools/website-to-markdown-llms-txt) — main content of web pages as Markdown for LLMs.

# Actor input Schema

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

Direct links to PDF, DOCX, XLSX, PPTX or HTML files (http or https, up to 50 MB each).

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

PDF pages to convert, e.g. '1-3,7'. Leave empty for all pages.

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

auto = OCR only pages without a text layer (scanned); always = OCR every page; never = no OCR.

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

Languages for OCR: spa, eng, fra, deu, ita, por, cat, nld.

## `includeChunks` (type: `boolean`):

Split the Markdown by headings into chunks that keep their heading path.

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

Maximum characters per RAG chunk.

## `includePerPage` (type: `boolean`):

Also return the Markdown of each PDF page separately.

## Actor input object example

```json
{
  "documentUrls": [
    "https://arxiv.org/pdf/1706.03762"
  ],
  "ocrMode": "auto",
  "ocrLanguages": [
    "spa",
    "eng"
  ],
  "includeChunks": true,
  "chunkSize": 2000,
  "includePerPage": 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 = {
    "documentUrls": [
        "https://arxiv.org/pdf/1706.03762"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("docflow-tools/document-to-markdown-rag").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://arxiv.org/pdf/1706.03762"] }

# Run the Actor and wait for it to finish
run = client.actor("docflow-tools/document-to-markdown-rag").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://arxiv.org/pdf/1706.03762"
  ]
}' |
apify call docflow-tools/document-to-markdown-rag --silent --output-dataset

```

## MCP server setup

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

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/SiKERdgu9CgBXR8pR/builds/JdPopttmg1JVtJyPg/openapi.json
