# Document to Markdown for RAG: PDF, DOCX, PPTX, XLSX, HTML (`unadata/docs-to-markdown`) Actor

Convert PDF, Word (DOCX), PowerPoint (PPTX), Excel (XLSX), HTML and TXT files from URLs into clean markdown and plain text with headings, lists and tables, plus ready-to-embed chunks for RAG and AI agents. Optional OCR for scanned pages. Pay per page.

- **URL**: https://apify.com/unadata/docs-to-markdown.md
- **Developed by:** [UnaData](https://apify.com/unadata) (community)
- **Categories:** AI, Developer tools, Agents
- **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 document converteds

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, DOCX, PPTX, XLSX, HTML

Convert **PDF, Word (DOCX), PowerPoint (PPTX), Excel (XLSX), HTML pages and text files** into **clean markdown and plain text**, with **ready-to-embed chunks** for RAG pipelines, vector databases and AI agents. Headings, lists and tables are preserved, every chunk knows its page number, and **OCR** for scanned pages and images is available when you need it.

Paste document URLs → get one JSON row per document: `markdown`, `text`, `chunks[]`, `tables[]`, `title`, `language`, `pages`, `wordCount`, `sha256`.

### Who is it for?

- **RAG / LLM developers**: turn PDFs and Office files into markdown chunks that you can embed straight into Pinecone, Qdrant, Weaviate, pgvector, Chroma or OpenAI vector stores.
- **AI agents (MCP)**: a "read this document" tool. Give the agent a URL and it gets clean markdown back.
- **Legal, finance and procurement teams**: convert annual reports, contracts and tender documents to searchable text.
- **Data teams**: extract tables from DOCX, PPTX, XLSX and HTML as arrays of rows.

### Features

- **One actor, many formats**: PDF, DOCX, PPTX, XLSX, HTML, TXT/MD/CSV/JSON, and PNG/JPG/TIFF/WebP images (with OCR). The type is detected from the file content, so URLs without an extension work too.
- **Markdown that keeps structure**:
  - PDF: titles and section headings (font size + numbered headings such as `3.2.1`), paragraphs, bullet lists, de-hyphenation, page numbers removed.
  - DOCX: headings, lists, bold/italic, links, tables.
  - PPTX: one `## Slide N: title` section per slide, bullets, tables, optional speaker notes.
  - XLSX: one markdown table per sheet, hidden sheets skipped.
- **RAG chunks**: paragraph- and sentence-aware splitting with configurable `chunkSize` and `chunkOverlap`. Each chunk has `index`, `text`, `page` and `tokensEstimate`.
- **Tables as data**: `tables[]` with `rows: string[][]` (DOCX, PPTX, XLSX, HTML).
- **OCR only when needed**: `ocr: "auto"` reads only pages with no text layer (scanned PDFs) and images. Tesseract, 100+ languages.
- **Privacy by default**: e-mail addresses and international phone numbers are masked (`[email removed]`) so personal contact data does not end up in your index. You can turn this off.
- **Cost control**: `maxPagesPerDocument`, `maxOcrPages`, `maxFileSizeMb`, and the run's maximum charge are all respected. The actor stops cleanly when the budget is used up.
- **No browser, no proxies**: plain HTTP downloads, fast and cheap. A 15-page PDF converts in about 1 second.

### Input example

```json
{
  "urls": [
    "https://arxiv.org/pdf/1706.03762v7",
    "https://example.com/annual-report.docx",
    "https://example.com/slides.pptx"
  ],
  "outputFormat": "markdown",
  "chunkSize": 1500,
  "chunkOverlap": 150,
  "maxPagesPerDocument": 50,
  "ocr": "auto",
  "ocrLanguages": ["eng"]
}
```

| Field | Default | Description |
|---|---|---|
| `urls` | – | Public document URLs. To convert your own file, upload it to an Apify key-value store and pass the record URL (the actor authenticates automatically for your own stores). |
| `outputFormat` | `markdown` | `markdown`, `text` or `both`. |
| `chunkSize` / `chunkOverlap` | 1500 / 150 | Chunk length and overlap in characters. `chunkSize: 0` disables chunking. |
| `maxPagesPerDocument` | 200 | PDF pages / PPTX slides / XLSX sheets per document. For DOCX, HTML and TXT one page = 3,000 characters. |
| `ocr` | `off` | `off`, `auto` (only pages without text + images), `force` (every PDF page). |
| `ocrLanguages` | `["eng"]` | Tesseract codes: `eng`, `deu`, `fra`, `spa`, `ita`, `por`, `nld`, `pol`, `rus`, `ukr`, `chi_sim`, `jpn`, … |
| `maxOcrPages` | 20 | OCR page cap for the whole run. |
| `includeTables` | `true` | Return tables as `rows` arrays as well. |
| `includeSpeakerNotes` | `false` | Add PowerPoint speaker notes. |
| `maxRowsPerSheet` | 1000 | Rows read per Excel sheet. |
| `redactContacts` | `true` | Mask e-mails and phone numbers. |
| `maxFileSizeMb` | 50 | Bigger files return an error row. |
| `maxItems` | 100 | Documents per run. |

### Output example

```json
{
  "sourceUrl": "https://arxiv.org/pdf/1706.03762v7",
  "fileName": "1706.03762v7.pdf",
  "fileType": "pdf",
  "mimeType": "application/pdf",
  "fileSizeBytes": 2215244,
  "pages": 15,
  "pagesConverted": 15,
  "billedPages": 15,
  "title": "Attention Is All You Need",
  "language": "eng",
  "markdown": "# Attention Is All You Need\n\n...\n\n## Abstract\n\nThe dominant sequence transduction models ...\n\n## 1 Introduction\n\n...\n\n#### 3.2.1 Scaled Dot-Product Attention\n\n...",
  "text": null,
  "chunks": [
    { "index": 0, "text": "## Provided proper attribution ...", "page": 1, "tokensEstimate": 147 },
    { "index": 1, "text": "## Abstract\n\nThe dominant sequence ...", "page": 1, "tokensEstimate": 321 }
  ],
  "chunkCount": 35,
  "tables": [],
  "tableCount": 0,
  "ocrPages": [],
  "wordCount": 6245,
  "charCount": 39997,
  "sha256": "…",
  "warnings": [],
  "convertedAt": "2026-11-16T03:00:00.000Z",
  "error": null
}
```

Every row has the same fields; a missing value is `null` (or an empty array). If a document cannot be converted, you get a row with `error` filled in (for example `Download failed: HTTP 404` or `Legacy binary Office format (.doc/.xls/.ppt) is not supported`), and you are **not charged** for it. A `RUN_SUMMARY` record in the key-value store lists converted/failed documents, pages, OCR pages and chunks.

#### Output fields

`sourceUrl`, `fileName`, `fileType` (pdf, docx, pptx, xlsx, html, text, image), `mimeType`, `fileSizeBytes`, `pages` (native page/slide/sheet count), `pagesConverted`, `billedPages`, `title`, `language` (ISO 639-3), `markdown`, `text`, `chunks[] {index, text, page, tokensEstimate}`, `chunkCount`, `tables[] {index, page, rows}`, `tableCount`, `ocrPages[]`, `wordCount`, `charCount`, `sha256` (to detect changed files), `warnings[]`, `convertedAt`, `error`.

### Pricing (pay per event)

| Event | Price | When |
|---|---|---|
| Document converted | $0.002 | each successfully converted document |
| Page converted | $0.0005 | each PDF page, PPTX slide, XLSX sheet, or 3,000 characters of DOCX/HTML/TXT |
| OCR page | $0.003 | each page or image read with OCR (instead of the page charge) |

Examples: a 15-page PDF costs **$0.0095**; 1,000 ten-page PDFs cost **$7**; a 2-page Word memo costs **$0.003**; a scanned 10-page PDF with OCR costs **$0.032**. Failed documents are free. Platform usage is included.

### Use with AI agents / MCP

This actor works as a tool for AI agents through the [Apify MCP server](https://mcp.apify.com). Add `unadata/docs-to-markdown` to your MCP client (Claude Desktop, Cursor, VS Code, LangGraph, OpenAI Agents) and the agent can call it with a list of URLs to get markdown and chunks back. Keep `chunkSize: 0` and `outputFormat: "markdown"` when the agent should read the whole document, or use chunks when it should index it.

It also works from code: the [Apify API](https://docs.apify.com/api/v2), the Python/JavaScript clients, LangChain (`ApifyDatasetLoader`), LlamaIndex, Make, Zapier and n8n.

### Limitations

- **PDF tables** are kept as text in reading order, not as markdown tables (DOCX, PPTX, XLSX and HTML tables are real tables). Multi-column layouts follow the PDF's reading order, which is usually correct for papers and reports.
- **Math formulas** come out as plain text approximations.
- **Images inside documents** are not described or OCRed (only scanned pages and image files are).
- Legacy **.doc/.xls/.ppt** and OpenDocument (ODT/ODS/ODP) files are not supported yet. Save them as DOCX/XLSX/PPTX or PDF.
- **Password-protected** PDFs and files behind a login are not supported. URLs must be publicly reachable.
- **HTML**: the actor converts the page as delivered by the server (no JavaScript rendering). For JavaScript-heavy websites use a web crawler first.
- OCR quality depends on the scan; it takes about 3–20 seconds per page. Use 2–4 GB memory for large OCR jobs.
- You are responsible for having the right to process the documents you submit. The actor does not store your documents after the run (results stay in your own dataset).

### FAQ

**How do I convert a PDF to markdown for RAG?** Put the PDF URL into `urls`, keep `outputFormat: "markdown"` and set `chunkSize` (1,000–2,000 characters works well for most embedding models). Each dataset row then has `chunks[]` that you can embed directly.

**Can I convert files from my computer?** Yes. Upload the file to an Apify key-value store (Console → Storage → Key-value stores, or the API) and use the record URL as input.

**How are pages counted for Word and HTML files?** These formats have no fixed pages, so every 3,000 characters of extracted text count as one page (at least one page per document).

**Does it OCR every PDF?** No. With `ocr: "auto"` only pages without a text layer are OCRed. With `ocr: "off"` (default) you get a warning when a PDF looks scanned.

**Which languages are supported?** Text extraction works for any language. OCR supports all Tesseract languages; set `ocrLanguages`, for example `["deu", "eng"]`.

**How do I detect changed documents?** Compare the `sha256` field between runs.

**Is it a PDF text extractor or a full document parser?** Both: you get plain text for search and markdown with structure for LLMs, plus tables as data for DOCX, PPTX, XLSX and HTML.

***

Keywords: pdf to markdown, docx to markdown, document to markdown, pdf text extractor, pdf parser api, convert pdf to text, rag document loader, chunking for embeddings, pptx to text, excel to markdown, html to markdown, ocr pdf, scanned pdf to text, llm document ingestion, mcp document tool.

# Actor input Schema

## `urls` (type: `array`):

Public URLs of documents: PDF, DOCX, PPTX, XLSX, HTML pages, TXT/MD/CSV, or images (PNG/JPG/TIFF, needs OCR). The type is detected from the file content. To convert your own file, upload it to an Apify key-value store and paste the record URL.

## `outputFormat` (type: `string`):

markdown keeps headings, lists and tables; text is plain text; both returns both fields.

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

Split each document into chunks of about this many characters for embeddings / RAG (paragraph- and sentence-aware). 0 = no chunks.

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

How many characters of the previous chunk are repeated at the start of the next one (max half of the chunk size).

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

Convert at most this many pages (PDF pages, PPTX slides, XLSX sheets; for DOCX/HTML/TXT a page = 3,000 characters). Caps cost on huge files.

## `ocr` (type: `string`):

off: text layer only (fast, cheapest). auto: OCR only PDF pages that have no text layer, and images. force: OCR every PDF page (up to Max OCR pages). OCR is billed per page.

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

Tesseract language codes, e.g. eng, deu, fra, spa, ita, por, nld, pol, rus, ukr, chi_sim, jpn. More languages = slower.

## `maxOcrPages` (type: `integer`):

Hard cap on OCR pages in the whole run (OCR takes ~5-20 s per page).

## `includeTables` (type: `boolean`):

Also return tables found in DOCX, PPTX, XLSX and HTML as arrays of rows (tables are always kept in the markdown).

## `includeSpeakerNotes` (type: `boolean`):

Append speaker notes to each slide.

## `maxRowsPerSheet` (type: `integer`):

Rows read from each XLSX sheet.

## `maxFileSizeMb` (type: `integer`):

Larger files are skipped with an error row.

## `maxItems` (type: `integer`):

Maximum number of documents to convert in this run.

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

Documents processed in parallel.

## `redactContacts` (type: `boolean`):

Replace e-mail addresses and international phone numbers (+...) in the output with \[email removed] / \[phone removed]. Keeps personal contact data out of your RAG index.

## Actor input object example

```json
{
  "urls": [
    "https://arxiv.org/pdf/1706.03762v7"
  ],
  "outputFormat": "markdown",
  "chunkSize": 1500,
  "chunkOverlap": 150,
  "maxPagesPerDocument": 15,
  "ocr": "off",
  "ocrLanguages": [
    "eng"
  ],
  "maxOcrPages": 20,
  "includeTables": true,
  "includeSpeakerNotes": false,
  "maxRowsPerSheet": 1000,
  "maxFileSizeMb": 50,
  "maxItems": 100,
  "maxConcurrency": 2,
  "redactContacts": true
}
```

# Actor output Schema

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

Converted documents: markdown, plain text, RAG chunks, tables and metadata (JSON, CSV, Excel via the dataset API).

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

RUN_SUMMARY record: documents converted/failed, pages, OCR pages, chunks, failures with reasons, duration.

# 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 = {
    "urls": [
        "https://arxiv.org/pdf/1706.03762v7"
    ],
    "chunkSize": 1500,
    "chunkOverlap": 150,
    "maxPagesPerDocument": 15,
    "ocr": "off"
};

// Run the Actor and wait for it to finish
const run = await client.actor("unadata/docs-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 = {
    "urls": ["https://arxiv.org/pdf/1706.03762v7"],
    "chunkSize": 1500,
    "chunkOverlap": 150,
    "maxPagesPerDocument": 15,
    "ocr": "off",
}

# Run the Actor and wait for it to finish
run = client.actor("unadata/docs-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 '{
  "urls": [
    "https://arxiv.org/pdf/1706.03762v7"
  ],
  "chunkSize": 1500,
  "chunkOverlap": 150,
  "maxPagesPerDocument": 15,
  "ocr": "off"
}' |
apify call unadata/docs-to-markdown --silent --output-dataset

```

## MCP server setup

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