# Convert PDF, Word & Excel URLs to Markdown + RAG Chunks (`craigmckee/document-to-markdown`) Actor

Convert document URLs (PDF, Word, PowerPoint, Excel, HTML, CSV, EPUB) into clean LLM-ready Markdown plus token-sized RAG chunks.

- **URL**: https://apify.com/craigmckee/document-to-markdown.md
- **Developed by:** [Print & Plan UK](https://apify.com/craigmckee) (community)
- **Categories:** AI, Developer tools
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $4.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

## Convert PDF, Word & Excel URLs to Markdown + RAG Chunks

**What it does:** turns public document links into clean Markdown and ready-to-embed RAG chunks, by Print & Plan UK. **You give it:** a list of document URLs (PDF, DOCX, PPTX, XLSX, HTML, CSV, EPUB), plus optional chunk size and overlap. **You get:** one dataset item per document with the full Markdown, chunks that keep their heading path and PDF page number, and token estimates. **Cost per run:** $0.004 per document (first 10 pages included) plus $0.0003 per extra page, so 100 ten-page PDFs cost $0.40; failed downloads are free. **Example inputs:** `https://arxiv.org/pdf/1706.03762`, `https://en.wikipedia.org/wiki/Markdown`, `https://calibre-ebook.com/downloads/demos/demo.docx`.

### Why use it?

- **One Actor for every format**: PDF, DOCX, PPTX, XLSX/XLS, HTML, CSV, JSON, XML, TXT. Most Store alternatives handle PDF only.
- **RAG-ready chunks**: paragraph-aware chunks with configurable size and overlap. Each chunk keeps its **heading path** (e.g. `Lists > Multi-level Lists`) and its **PDF page number**, so you can cite sources.
- **Good PDF text**: uses PDFium, which keeps word spacing on LaTeX and academic PDFs that trip up other extractors.
- **Token estimates** for every document and chunk, so you can plan LLM costs.
- **Fair pricing**: you pay per converted document. Failed downloads and conversions are free.

### How to use

1. Paste one or more document URLs into **Document URLs**.
2. Optionally adjust chunk size and overlap (defaults: 2,000 characters, roughly 500 tokens, with 200 characters of overlap).
3. Click **Start**. Each document becomes one dataset item. Export as JSON, CSV or Excel, or use the API, Make, Zapier, n8n or LangChain.

### Input example

```json
{
  "urls": [
    "https://arxiv.org/pdf/1706.03762",
    "https://calibre-ebook.com/downloads/demos/demo.docx",
    "https://filesamples.com/samples/document/xlsx/sample1.xlsx"
  ],
  "includeMarkdown": true,
  "includeChunks": true,
  "chunkSize": 2000,
  "chunkOverlap": 200
}
```

### Output example (trimmed)

```json
{
  "url": "https://arxiv.org/pdf/1706.03762",
  "httpStatus": 200,
  "fileType": "pdf",
  "sizeBytes": 2215244,
  "pageCount": 15,
  "charCount": 39862,
  "approxTokens": 9966,
  "markdown": "<!-- page 1 -->\nProvided proper attribution is provided, Google hereby grants permission to …",
  "chunkCount": 27,
  "chunks": [
    {"index": 0, "page": 1, "headingPath": "", "charCount": 1740, "approxTokens": 435, "text": "Provided proper attribution is provided, …"}
  ]
}
```

A DOCX document produces a `headingPath` for each chunk, for example `"Lists > Multi-level Lists"`. Spreadsheets become Markdown tables, one section per sheet.

### Pricing (pay per event)

| Event | Price |
|---|---|
| Document converted (includes the first 10 pages) | $0.004 |
| Each extra page after 10 (PDF/PPTX) | $0.0003 |

Examples: a 15-page PDF costs $0.0055. 1,000 short DOCX or HTML files cost $4. Downloads that fail, files that are too large, and unsupported files are **not charged**. Set a **maximum cost per run** in the run options and the Actor stops cleanly at that limit.

### FAQ

**Does it OCR scanned PDFs?** No. Image-only PDFs return little or no text, and the item has a `warning` field. OCR may be added later.

**What's the file size limit?** 50 MB by default (`maxFileSizeMb`, up to 200).

**Can it read private files?** Only URLs the Actor can download anonymously. It never logs in. For files on Google Drive, Dropbox and similar services, use a public direct-download link. Private network addresses are blocked.

**Is the output good for embeddings?** Yes. Chunks split on paragraph and line boundaries, start their overlap on a word boundary, and never exceed `chunkSize`.

### Legal

Only convert documents you have the right to process. The Actor fetches each URL once, exactly as a browser download would, and does not bypass logins or paywalls.

Built with the Apify SDK for Python, Microsoft MarkItDown (MIT) and PDFium (pypdfium2, Apache-2.0/BSD).

### More tools from this developer

- [Bulk Domain Intel (RDAP)](https://apify.com/craigmckee/domain-intel-rdap): domain age, expiry, registrar, DNS and an SPF/DMARC/DKIM grade.
- [Website Tech Stack Detector](https://apify.com/craigmckee/tech-stack-detector): CMS, ecommerce, analytics and CDN, with evidence for each detection.
- [Wayback Machine Change Tracker](https://apify.com/craigmckee/wayback-change-tracker): capture history and a text diff between archived versions.
- [Broken Link & Redirect Chain Auditor](https://apify.com/craigmckee/site-link-auditor): broken links, redirect chains, mixed content and noindex pages.

# Actor input Schema

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

Public URLs of documents to convert. Supported: PDF, DOCX, PPTX, XLSX/XLS, HTML, CSV, TXT, JSON, XML, EPUB. Text-based PDFs only (no OCR).

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

Return the whole document as one Markdown string in the `markdown` field.

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

Split the Markdown into overlapping chunks (with heading path and token estimate) ready for embeddings.

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

Target maximum characters per chunk (~4 characters per token). 2,000 ≈ 500 tokens.

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

Characters repeated from the end of the previous chunk at the start of the next one.

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

Documents larger than this are skipped (and not charged).

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

How many documents to download and convert in parallel.

## Actor input object example

```json
{
  "urls": [
    "https://arxiv.org/pdf/1706.03762",
    "https://en.wikipedia.org/wiki/Markdown"
  ],
  "includeMarkdown": true,
  "includeChunks": true,
  "chunkSize": 2000,
  "chunkOverlap": 200,
  "maxFileSizeMb": 50,
  "maxConcurrency": 4
}
```

# 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 = {
    "urls": [
        "https://arxiv.org/pdf/1706.03762",
        "https://en.wikipedia.org/wiki/Markdown"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("craigmckee/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://arxiv.org/pdf/1706.03762",
        "https://en.wikipedia.org/wiki/Markdown",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("craigmckee/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://arxiv.org/pdf/1706.03762",
    "https://en.wikipedia.org/wiki/Markdown"
  ]
}' |
apify call craigmckee/document-to-markdown --silent --output-dataset

```

## MCP server setup

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