# Document to Markdown for AI Agents: PDF, Word, Excel, OCR (`greenrun/document-to-markdown`) Actor

Convert PDF, DOCX, PPTX, XLSX, EPUB, HTML and scanned images to clean Markdown with tables, page markers and OCR. Built for LLMs, RAG pipelines and AI agents via MCP. Failed downloads and unsupported files are free.

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

## Pricing

from $5.00 / 1,000 documents

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 AI Agents

Convert **PDF, Word, PowerPoint, Excel, EPUB, HTML, CSV** and **scanned images** into clean Markdown that LLMs can read. Give it links, get back one Markdown document per link, with tables, page markers and OCR for scans. **Failed downloads and unsupported files are free.**

### What it does

- **PDF to Markdown** page by page, with `<!-- page N -->` markers so your agent can cite page numbers.
- **PDF tables to Markdown tables** in reading order, without duplicating the table text. Works for fully ruled tables and for tables ruled only horizontally; layout boxes and figures stay as text.
- **OCR for scanned PDFs and images** (Tesseract) in `auto` mode: only pages without a text layer are OCR-ed, so you pay for OCR only where it is needed.
- **Word, PowerPoint, Excel, EPUB, HTML, CSV, JSON, XML** to Markdown, tables included.
- One dataset item per URL, in input order, with `status`, `error`, page counts and the exact events you were charged for.

### Why use it

- **Made for agents and RAG.** Output is plain Markdown plus a few numbers, small enough to drop into a prompt or a vector store.
- **Pay per document and page.** A typical document costs $0.005; links that fail to download and unsupported files cost nothing.
- **Limited permissions.** The Actor only touches its own run storage, nothing else in your Apify account.
- **No tricks.** It downloads exactly the links you give it, without proxies or CAPTCHA solving. Links behind a login or bot protection fail with a clear error, free of charge.

### Supported formats

| Format | Notes |
|---|---|
| PDF | Text, ruled tables, page markers, OCR for scanned pages |
| DOCX, PPTX, XLSX, XLS | Text and tables |
| EPUB, HTML, CSV, JSON, XML, TXT, IPYNB | Converted to Markdown |
| PNG, JPEG, TIFF (multi-page), GIF, BMP, WEBP | OCR |

Not supported: legacy `.doc` and `.ppt`, ZIP archives, password-protected PDFs.

### How to use

#### In Apify Console

Paste document links into **Document URLs** and press **Start**. Each link becomes one row in the dataset.

#### From an AI agent (MCP)

Connect any MCP client to the Apify MCP server with only this Actor as a tool:

```
https://mcp.apify.com?tools=greenrun/document-to-markdown
```

The agent passes `urls` and reads `markdown` from the result.

#### Through the API

```bash
curl -X POST "https://api.apify.com/v2/acts/greenrun~document-to-markdown/run-sync-get-dataset-items" \
  -H "Authorization: Bearer <APIFY_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{"urls": ["https://arxiv.org/pdf/1706.03762"]}'
```

### Input

| Field | Default | Description |
|---|---|---|
| `urls` | | Document links (http or https), one dataset item each |
| `ocr` | `auto` | `auto`: only scans and images; `force`: every page; `off`: never |
| `ocrLanguages` | `eng` | Tesseract codes joined with `+`. Available: eng, pol, deu, fra, spa, ita, por, nld |
| `extractTables` | `true` | Render ruled PDF tables as Markdown tables |
| `pageMarkers` | `true` | Insert `<!-- page N -->` before each PDF page |
| `maxPages` | `200` | Stop converting a PDF after this many pages |
| `maxFileSizeMb` | `50` | Larger files fail with an error, free of charge |
| `timeoutSecsPerDocument` | `600` | PDFs and scans stop at the next page after this time and return the pages done so far, with a warning. A conversion that hangs is stopped 120 s later and returns the pages done |

### Output

```json
{
  "url": "https://arxiv.org/pdf/1706.03762",
  "status": "success",
  "format": "pdf",
  "fileName": "1706.03762v7.pdf",
  "contentType": "application/pdf",
  "sizeBytes": 2215244,
  "title": null,
  "pageCount": 15,
  "pagesProcessed": 15,
  "truncated": false,
  "tablesFound": 0,
  "ocrPages": 0,
  "characters": 39971,
  "markdown": "<!-- page 1 -->\n\nProvided proper attribution is provided, Google hereby grants permission to ...",
  "markdownUrl": null,
  "warnings": [],
  "billableEvents": { "document": 1, "extra-page": 0, "ocr-page": 0 },
  "workGbSecs": 9.6,
  "processingMs": 2701,
  "error": null
}
```

This is real output from a run on 16 November 2026, with the Markdown shortened (`workGbSecs`, the run time the document used, comes from a run on 21 November 2026). `title` comes from the document's metadata and is `null` when the file has none, as here. The tables of this paper are drawn with three rules and merged headers, so they come out as text rather than as a broken table. When the Markdown is larger than 5 MB, `markdown` holds a preview and `markdownUrl` links to the full text in the run's key-value store.

### Pricing

Pay per event, no subscription:

| Event | Price | When |
|---|---|---|
| Actor start | $0.0045 per GB of memory | Each run: $0.009 at the default 2 GB |
| Document | $0.005 | Each document downloaded and recognized as a supported format, including up to 20 PDF pages and 48 GB-seconds of work (24 s at 2 GB); one more for each further started 48 GB-seconds that its page events do not cover (a very slow download, very complex pages, a large Office file) |
| Extra PDF page | $0.0002 | Each PDF page above 20 |
| OCR page | $0.01 | Each page read with OCR, charged before the OCR runs |

Free: links that fail to download, files over `maxFileSizeMb` and unsupported formats. A document is charged once its file is recognized, also when the conversion then fails (a damaged or password-protected file) or stops at `timeoutSecsPerDocument` (you get the pages done so far). `billableEvents` and `workGbSecs` in each item show what it was charged for.

Examples: 100 text PDFs of up to 20 pages cost $0.50 plus the start. A 71-page PDF full of tables (IRS Publication 15-T) costs $0.005 + 51 × $0.0002 = $0.0152. A 120-page PDF costs $0.005 + 100 × $0.0002 = $0.025. A 10-page scan costs $0.005 + 10 × $0.01 = $0.105.

Every run stays within what its charges pay for. A run whose links only fail (dead hosts, missing files) stops once its Actor start is used up and lists the links it did not try in the `RUN-REPORT` record (`notProcessedInputs`); start them again in a new run. You can cap the cost of a run with the maximum charge in the run options (at least $0.025); the Actor stops cleanly at that limit and does not start documents it cannot charge for.

### Limits

- Tables are detected in PDFs that draw ruled lines; tables without lines, and tables too sparse or irregular to rebuild reliably, come out as text.
- HTML pages are converted whole, navigation included. To crawl websites, use a web crawler Actor.
- OCR quality depends on the scan; 300 dpi scans work best.
- Links must be publicly downloadable; private networks and local addresses are blocked.

### FAQ

**Do you keep my documents?** No. Files are downloaded into the run's temporary storage and deleted after conversion. The Markdown stays in your run's dataset in your own Apify account, under your data retention settings.

**Can my agent use it without code?** Yes, through the Apify MCP server link above.

**Something does not convert well?** Open an issue on the Actor's **Issues** tab with the link (if it is public), and it will be looked at.

# Actor input Schema

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

Public http or https links to documents. Supported: PDF, DOCX, PPTX, XLSX, XLS, EPUB, HTML, CSV, JSON, XML, TXT and images (PNG, JPEG, TIFF, GIF, BMP, WEBP) for OCR. Each URL becomes one dataset item, in the same order.

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

auto: OCR only PDF pages without a text layer (scans) and images. force: OCR every page, for PDFs with a broken text layer. off: never run OCR.

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

Tesseract language codes joined with +, for example eng+pol. Available: eng, pol, deu, fra, spa, ita, por, nld.

## `extractTables` (type: `boolean`):

Render PDF tables that have ruled lines as Markdown tables. Word, PowerPoint and Excel tables are always converted.

## `pageMarkers` (type: `boolean`):

Insert an HTML comment such as  before each PDF page, so you can cite page numbers.

## `maxPages` (type: `integer`):

Stop converting a PDF after this many pages. Pages above 20 are billed as extra pages.

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

Larger files are skipped with an error and are not charged.

## `timeoutSecsPerDocument` (type: `integer`):

PDFs and scans stop at the next page after this time and return the pages done so far, with a warning; only those pages are charged. A conversion that hangs is stopped 120 s later and returns the pages done.

## Actor input object example

```json
{
  "urls": [
    "https://arxiv.org/pdf/1706.03762"
  ],
  "ocr": "auto",
  "ocrLanguages": "eng",
  "extractTables": true,
  "pageMarkers": true,
  "maxPages": 200,
  "maxFileSizeMb": 50,
  "timeoutSecsPerDocument": 600
}
```

# 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"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("greenrun/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"] }

# Run the Actor and wait for it to finish
run = client.actor("greenrun/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"
  ]
}' |
apify call greenrun/document-to-markdown --silent --output-dataset

```

## MCP server setup

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