# Document to Markdown: PDF, Word, Excel & OCR for RAG (`vinflow/doc-to-markdown`) Actor

Convert PDF, DOCX, PPTX, XLSX, HTML, EPUB and images to clean Markdown for LLMs and RAG. Scanned PDFs and photos are OCR'd automatically (image to text, PDF to text), and output can be split into chunks. Failed files are never charged.

- **URL**: https://apify.com/vinflow/doc-to-markdown.md
- **Developed by:** [VINFlow](https://apify.com/vinflow) (community)
- **Categories:** AI, Developer tools, Agents
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.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 — PDF, Word, PowerPoint, Excel & OCR for RAG

Convert documents into clean Markdown that LLMs, RAG pipelines and AI agents can read. Give it links to the files; it returns one dataset item per file with the Markdown text and, if you ask, ready-made chunks.

### What it handles

| Input | How it is converted |
|---|---|
| PDF with a text layer | Text extracted page by page, hard-wrapped lines rejoined into paragraphs, hyphenated words repaired |
| Scanned PDF | Pages with no text layer are OCR'd automatically. A mixed PDF only pays OCR on the scanned pages |
| Word (DOCX) | Headings, lists, tables, bold and italic preserved |
| PowerPoint (PPTX) | One section per slide, including notes and tables |
| Excel (XLSX, XLS), CSV | One Markdown table per sheet |
| Images (PNG, JPG, TIFF, WebP, GIF, BMP) | OCR, including multi-page TIFF |
| HTML, EPUB, JSON, XML, Outlook MSG | Converted to Markdown |

OCR languages: English, French, German, Spanish, Portuguese, Italian, Dutch, Simplified Chinese and Japanese. Combine them like `eng+fra`.

### Input

```json
{
  "sources": [
    { "url": "https://arxiv.org/pdf/1706.03762" },
    { "url": "https://example.com/contract-scan.pdf" }
  ],
  "ocrMode": "auto",
  "ocrLanguages": "eng",
  "chunkSize": 2000,
  "chunkOverlap": 200
}
```

- **ocrMode**: `auto` (default) OCRs only pages that have no text. `always` OCRs every page, which helps when a PDF's text layer is garbled. `never` skips OCR.
- **chunkSize**: set it above 0 to also get a `chunks` array, split at headings and paragraphs. Each heading stays attached to the text under it.
- To convert files on your computer, upload them to an Apify key-value store or any file host and pass the links.

### Output

```json
{
  "url": "https://arxiv.org/pdf/1706.03762",
  "success": true,
  "fileName": "1706.03762",
  "fileType": "pdf",
  "pages": 15,
  "ocrPages": 0,
  "characters": 39518,
  "markdown": "<!-- page 1 -->\n\nAttention Is All You Need ...",
  "chunks": ["...", "..."]
}
```

A file that fails (broken link, too large, password-protected) still gets an item, with `success: false` and an `error` message. You are not charged for it.

### Pricing

You pay per event:

- **Document converted**: one charge per successful file
- **OCR page**: one charge per page that needed OCR

Failed files are free. To cap spending, set a maximum cost per run in the run options; the actor stops cleanly when it reaches the cap.

### Use with AI agents

The input and output are plain JSON, so it works as a tool for agents through the Apify MCP server, the API, LangChain, LlamaIndex, Make, Zapier or n8n. A typical pipeline is: find documents → convert them with this actor → embed the `chunks` → store them in a vector database.

### Limits

- Files up to 50 MB by default (`maxFileSizeMb` raises it to 500 MB)
- Password-protected PDFs are not supported
- Layout-heavy PDFs (multi-column magazines, forms) come out as reading-order text, not as a reproduction of the layout

# Actor input Schema

## `sources` (type: `array`):

Links to the files to convert: PDF, DOCX, PPTX, XLSX/XLS, HTML, EPUB, CSV, JSON, XML, Outlook MSG, or images (PNG, JPG, TIFF, WebP, GIF, BMP). Files uploaded in Apify Console get a URL you can paste here.

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

auto: OCR only PDF pages with no text layer, and all images. always: OCR every PDF page (useful when the text layer is garbage). never: skip OCR.

## `ocrLanguages` (type: `string`):

Tesseract language codes joined with +. Installed: eng, fra, deu, spa, por, ita, nld, chi_sim, jpn. Example: eng+fra

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

Also split the Markdown into chunks of at most this many characters, breaking at headings and paragraphs. 0 turns chunking off.

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

How many characters from the end of one chunk to repeat at the start of the next.

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

Skip files larger than this.

## Actor input object example

```json
{
  "sources": [
    {
      "url": "https://arxiv.org/pdf/1706.03762"
    }
  ],
  "ocrMode": "auto",
  "ocrLanguages": "eng",
  "chunkSize": 0,
  "chunkOverlap": 200,
  "maxFileSizeMb": 50
}
```

# Actor output Schema

## `documents` (type: `string`):

All converted documents with their Markdown, metadata and chunks.

# 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 = {
    "sources": [
        {
            "url": "https://arxiv.org/pdf/1706.03762"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("vinflow/doc-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 = { "sources": [{ "url": "https://arxiv.org/pdf/1706.03762" }] }

# Run the Actor and wait for it to finish
run = client.actor("vinflow/doc-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 '{
  "sources": [
    {
      "url": "https://arxiv.org/pdf/1706.03762"
    }
  ]
}' |
apify call vinflow/doc-to-markdown --silent --output-dataset

```

## MCP server setup

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