# Document to Markdown for AI & RAG: PDF, Word, PowerPoint, Excel (`patrickballard/document-to-markdown`) Actor

Turn PDF, DOCX, PPTX, XLSX, CSV, EPUB and HTML file URLs into clean Markdown for LLMs, with optional RAG chunks that keep their heading path, plus word and token counts. One flat price per document, no per-page fees.

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

## Pricing

from $6.00 / 1,000 documents converted

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/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 AI & RAG: PDF, Word, PowerPoint, Excel

Give it links to documents and get back **clean Markdown** your LLM can read: headings, lists and tables kept, junk whitespace removed. Optionally it splits each document into **RAG-ready chunks** that remember which heading they came from.

**Formats:** PDF · Word (DOCX) · PowerPoint (PPTX) · Excel (XLSX, XLS) · CSV · EPUB · HTML · TXT · JSON · XML

- **One price per document**, no per-page fees.
- **Free when it fails.** A broken file, a 404 or an unsupported type gives an error row and isn't charged.
- **RAG chunks** split by heading, then by size, with optional overlap. Each chunk has its `headingPath`, e.g. `["User Guide", "Install", "Linux"]`.
- **Word and token counts** for budgeting LLM calls.
- **Works with AI agents** through Apify's MCP server, and from Make, Zapier, n8n or the API.
- Handles download links with no file extension (it reads `Content-Disposition` and `Content-Type`).

### Output (one row per document)

```json
{
  "url": "https://example.com/files/q3-report.docx",
  "fileName": "q3-report.docx",
  "fileType": "docx",
  "bytes": 28254,
  "title": "Quarterly Report",
  "charCount": 4120,
  "wordCount": 690,
  "approxTokens": 1030,
  "markdown": "# Quarterly Report\n\n# Revenue\n\nRevenue grew 12% to £1.2m.\n\n| Region | Sales |\n| --- | --- |\n| UK | 900 |\n…",
  "chunks": [
    { "index": 0, "headingPath": ["Quarterly Report"], "text": "# Quarterly Report", "charCount": 18 },
    { "index": 1, "headingPath": ["Revenue"], "text": "# Revenue\n\nRevenue grew 12%…", "charCount": 92 }
  ],
  "error": null
}
```

### Pricing

**$0.006 per document converted** ($6 per 1,000), whatever its length up to the size limit. Failed documents are free. Set a maximum cost per run and the Actor stops cleanly when it's reached.

### Limits (honest)

- **No OCR.** Scanned or image-only PDFs come back as an error ("No text found"), and you aren't charged.
- PDF layout is reconstructed from the text layer. Complex multi-column layouts can come out in an odd reading order.
- Max 200 MB per file (default 50 MB). Up to 1,000 URLs per run.
- It fetches only the links you give it, and only public internet addresses. Use documents you have the right to process.
- Nothing is stored beyond your own run's dataset.

### FAQ

**Can I send Google Drive or Dropbox links?** Use a direct-download link (Dropbox: `?dl=1`; Google Drive: `uc?export=download&id=…`).

**What powers it?** Microsoft's open-source [MarkItDown](https://github.com/microsoft/markitdown), plus a fallback for Word files it can't open.

**Found a file it gets wrong?** Open an issue with the link (if it's public) and I'll look at it.

# Actor input Schema

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

Direct links to files: PDF, DOCX, PPTX, XLSX/XLS, CSV, EPUB, HTML, TXT, JSON, XML. Up to 1000 per run.

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

0 = no chunks. Otherwise split each document by headings, then into chunks of about this many characters (200–50000). Each chunk keeps its heading path.

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

Characters repeated from the end of one chunk at the start of the next (max half the chunk size).

## `includeMarkdown` (type: `boolean`):

Turn off to return only chunks and counts (smaller output).

## `maxFileMb` (type: `integer`):

Larger files are skipped (not charged).

## Actor input object example

```json
{
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "chunkSize": 0,
  "chunkOverlap": 0,
  "includeMarkdown": true,
  "maxFileMb": 50
}
```

# Actor output Schema

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

One row per document: Markdown, title, stats and optional chunks.

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

Number of documents converted and failed.

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

```

## MCP server setup

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