# PDF & Document to Markdown (OCR) (`merrowick/pdf-to-markdown`) Actor

Convert PDFs, DOCX and images you supply into clean Markdown or plain text, with OCR for scanned pages and RAG-ready chunks.

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

## Pricing

from $1.00 / 1,000 text page 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

## PDF & Document to Markdown (OCR)

Turn **PDFs, Word (DOCX) files and images** into clean **Markdown or plain text**, ready for LLMs, RAG pipelines, search indexes and data entry. Scanned pages are read with OCR automatically, and you can get the output pre-split into overlapping chunks for embeddings.

### Use cases

- Feed reports, papers, manuals and contracts into RAG / vector databases
- Convert scanned invoices, letters or forms to searchable text
- Bulk-convert DOCX documentation to Markdown (headings, lists, tables kept)
- Extract text from screenshots and photos of documents

### Input example

```json
{
  "fileUrls": ["https://arxiv.org/pdf/1706.03762", "https://example.com/scan.png"],
  "kvStoreFiles": ["my-store-id/contract.docx"],
  "outputFormat": "markdown",
  "ocr": "auto",
  "language": "eng",
  "chunkSize": 1500,
  "chunkOverlap": 200
}
```

- `ocr`: `auto` (only pages without a text layer), `on` (every page), `off`
- `language`: Tesseract codes, combine with `+` (installed: eng, deu, fra, spa, ita, por, nld)
- `chunkSize` 0 disables chunking; chunks prefer paragraph/sentence boundaries

### Output (one item per file)

`source, status (ok | blocked | failed), fileType, httpStatus, pages, textPages, ocrPages, chars, content, chunks, error`. PDF Markdown output has a `## Page N` heading per page.

### Pricing (pay per event)

| Event | Price | When |
|---|---|---|
| `text-page` | $0.001 | each PDF page read from its text layer, or each ~3,000 characters of DOCX |
| `ocr-page` | $0.005 | each scanned page or image read with OCR |

No start fee. Failed, blocked or unsupported files and pages above `maxPages` are **not charged**. Standard Apify platform usage applies according to your plan.

### Privacy and responsible use

- Only the exact URLs / store keys you provide are fetched; nothing is crawled, no proxies or anti-bot evasion are used, and an honest user agent identifies the Actor.
- If a server answers 401, 403 or 429 the file is marked `blocked`, not retried around, and not charged.
- Documents can contain personal data. Files are processed in memory for the run only; their content is never written to logs. The extracted text goes only to your own run dataset, which follows your Apify data retention settings. Only process files you have the right to process.

### Limits

- Max 100 MB per file; default 500 pages per file.
- Password-protected PDFs, legacy .doc, XLSX/PPTX are not supported yet.
- OCR quality depends on scan quality; handwriting is not reliably recognised.
- PDF Markdown is text-per-page (no table reconstruction yet); DOCX keeps headings, lists and tables.

### Open-source components (all permissive, commercial use OK)

| Library | License |
|---|---|
| pypdfium2 / PDFium | Apache-2.0 / BSD-3-Clause |
| python-docx | MIT |
| pytesseract | Apache-2.0 |
| Tesseract OCR | Apache-2.0 |
| Pillow | MIT-CMU (HPND) |
| httpx | BSD-3-Clause |
| Apify SDK for Python | Apache-2.0 |

PyMuPDF / pymupdf4llm were deliberately not used because they are AGPL-3.0.

### Use with AI agents (MCP)

This Actor works as a tool in any MCP client (Claude, Cursor, VS Code, LangGraph, etc.) through Apify's hosted MCP server.

Add it to your MCP client config (OAuth sign-in opens on first use):

```json
{
  "mcpServers": {
    "pdf-to-markdown": { "url": "https://mcp.apify.com?tools=merrowick/pdf-to-markdown" }
  }
}
```

Or with a token header: `"headers": { "Authorization": "Bearer <APIFY_TOKEN>" }`. The CLI can write the config for you: `apify mcp install cursor`.

The tool appears as `merrowick--pdf-to-markdown`. Only `fileUrls` is needed. Set a small `maxPages` to preview long documents cheaply, and `chunkSize` (e.g. 2000) for RAG-ready chunks.

Example tool-call input:

```json
{ "fileUrls": ["https://arxiv.org/pdf/1706.03762"], "maxPages": 2 }
```

Example output item (one per input):

```json
{
  "source": "https://arxiv.org/pdf/1706.03762",
  "status": "ok",
  "fileType": "pdf",
  "httpStatus": 200,
  "pages": 15,
  "textPages": 2,
  "ocrPages": 0,
  "chars": 7132,
  "content": "## Page 1\n\n...Attention Is All You Need\nAshish Vaswani...",
  "chunks": null,
  "error": null
}
```

The tool returns the run status and dataset ID; read the items with `get-dataset-items` (added automatically by the MCP server). Failed and blocked items are never charged.

### Call it from code

API (sync, returns dataset items):

```bash
curl -X POST "https://api.apify.com/v2/acts/merrowick~pdf-to-markdown/run-sync-get-dataset-items" \
  -H "Authorization: Bearer $APIFY_TOKEN" -H "Content-Type: application/json" \
  -d '{ "fileUrls": ["https://arxiv.org/pdf/1706.03762"], "maxPages": 2 }'
```

Python (`pip install apify-client`):

```python
from apify_client import ApifyClient
client = ApifyClient("<APIFY_TOKEN>")
run = client.actor("merrowick/pdf-to-markdown").call(run_input={ "fileUrls": ["https://arxiv.org/pdf/1706.03762"], "maxPages": 2 })
items = client.dataset(run["defaultDatasetId"]).list_items().items
```

JavaScript (`npm i apify-client`):

```js
import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('merrowick/pdf-to-markdown').call({ "fileUrls": ["https://arxiv.org/pdf/1706.03762"], "maxPages": 2 });
const { items } = await client.dataset(run.defaultDatasetId).listItems();
```

# Changelog

This Actor's version history is a separate document: https://apify.com/merrowick/pdf-to-markdown/changelog.md

# Actor input Schema

## `fileUrls` (type: `array`):

Main input. List of direct http(s) links to PDF, DOCX, PNG or JPEG files, e.g. \["https://arxiv.org/pdf/1706.03762"]. Only these exact URLs are downloaded; nothing is crawled. One result item per file.

## `kvStoreFiles` (type: `array`):

Optional alternative to fileUrls: files already in an Apify key-value store, as 'storeId/key' or just 'key' (this run's default store). Most agents can ignore this.

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

'markdown' (default): keeps page headings, lists and DOCX tables. 'text': plain text.

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

'auto' (default): OCR only scanned pages without a text layer. 'on': OCR every page (slower, costs more). 'off': never OCR; images are skipped.

## `language` (type: `string`):

Tesseract OCR language code(s), default 'eng'. Combine with '+', e.g. 'eng+fra'. Installed: eng, deu, fra, spa, ita, por, nld.

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

Split the text into chunks of about this many characters for RAG/embeddings (returned in 'chunks'). 0 (default) = no chunking. 1500-4000 is typical.

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

Characters shared between consecutive chunks when chunkSize > 0. Default 200.

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

Maximum pages converted per file (default 500). Pages beyond this are skipped and not charged. Agents should set a small value (e.g. 5) to preview long documents cheaply.

## `ocrDpi` (type: `integer`):

Render resolution for OCR of scanned PDF pages (100-400, default 300). Lower is faster, higher is more accurate.

## Actor input object example

```json
{
  "fileUrls": [
    "https://arxiv.org/pdf/1706.03762"
  ],
  "outputFormat": "markdown",
  "ocr": "auto",
  "language": "eng",
  "chunkSize": 0,
  "chunkOverlap": 200,
  "maxPages": 500,
  "ocrDpi": 300
}
```

# Actor output Schema

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

One item per input file: status, fileType, page counts, content (Markdown or text), optional chunks, error.

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

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

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

```

## MCP server setup

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