# PDF to Text & Markdown Extractor: OCR, DOCX, RAG chunks (`publicrecords/pdf-docx-to-markdown`) Actor

Turn PDF and Word files into clean Markdown text. Scanned pages are read with OCR, and the text comes split into RAG-ready chunks with heading paths.

- **URL**: https://apify.com/publicrecords/pdf-docx-to-markdown.md
- **Developed by:** [Public Records](https://apify.com/publicrecords) (community)
- **Categories:** AI, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 0.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

## PDF to Text & Markdown Extractor: OCR, DOCX, RAG chunks

Give it links to PDF or Word (.docx) files. It returns each document as clean Markdown text, reads scanned pages with OCR, and splits the text into chunks ready for a vector database or an LLM prompt.

### Who it is for

- Teams building RAG search or chatbots over PDFs, reports, papers and contracts.
- AI agents that need the text of a PDF or DOCX link as Markdown.
- Anyone who needs PDF to text in bulk without a separate OCR or AI API.

### What you get for each document

| Field | What it is |
|---|---|
| `markdown` | The whole document as Markdown: headings, lists, tables, `<!-- page N -->` markers for PDFs |
| `chunks` | Text chunks with `headingPath`, character offsets and a token estimate |
| `title`, `fileType`, `pageCount`, `pagesConverted` | Document facts |
| `ocrPages`, `textLayerPages` | Which pages were read with OCR and which from the text layer |
| `chars`, `tokensEstimate`, `chunkCount` | Size of the text |
| `sha256`, `fileBytes`, `finalUrl` | File identity |

Turn on **One row per chunk** to get one dataset row per chunk instead.

### Sample input

```json
{
  "documentUrls": [
    "https://arxiv.org/pdf/1706.03762",
    "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/skew.pdf"
  ],
  "ocrMode": "auto",
  "ocrLanguage": "eng",
  "chunkSize": 400,
  "chunkOverlap": 40
}
```

### Sample output (from a real run, vGkUDMwrAEmbFAxKQ, second document)

```json
{
  "url": "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/skew.pdf",
  "fileName": "skew.pdf",
  "fileType": "pdf",
  "title": null,
  "pageCount": 1,
  "pagesConverted": 1,
  "textLayerPages": 0,
  "ocrPages": [
    1
  ],
  "ocrLanguage": "eng",
  "chars": 4534,
  "tokensEstimate": 1134,
  "chunkCount": 4,
  "secondsToConvert": 2.68,
  "markdown": "<!-- page 1 -->\n\nThe LinnSequencer\n\n32 Track MIDIS\n\nequence Recorder\n\nThe LinnSequencer is a state-of-the-art composition and performance tool for the professional musician. It is\n\nextremely powerful, yet amazingly simple to learn and use. It ’s many remarkable features include:\n\n* Operation is simi ...",
  "chunks": [
    {
      "index": 0,
      "headingPath": "",
      "startChar": 0,
      "endChar": 1477,
      "chars": 1477,
      "tokensEstimate": 370,
      "text": "<!-- page 1 -->\n\nThe LinnSequencer\n\n32 Track MIDIS\n\nequence Recorder\n\nThe LinnSequencer is a state-of-the-art composition and performance tool for the professional musician. It is\n\nextremely powerful, ..."
    }
  ]
}
```

### Price

Pay per event. You only pay for documents that convert.

| Event | Price |
|---|---|
| Actor start (per GB of memory, once per run; default 2 GB = $0.005) | $0.0025 |
| Document converted (includes its first 20 text pages and chunking) | $0.004 |
| Extra text page (each PDF text page after the first 20) | $0.0003 |
| OCR page (each page read with OCR: scanned pages, and on Auto pages with under 25 characters that contain an image) | $0.002 |

Examples: a 15-page text PDF costs $0.009 ($0.005 start + $0.004 document) in a run with the default 2 GB memory; a 142-page PDF costs $0.0456; a 4-page scan costs $0.017.

### PDF to text with OCR for scanned pages

With OCR on **Auto**, pages that have no text layer (scans, photos of pages) are read with Tesseract OCR. Pages with almost no text (under 25 characters) that contain an image are also read with OCR and charged as OCR pages. Pages with more text than that are never OCRed or charged for OCR. Choose the OCR language for non-English scans (English, French, German, Spanish, Portuguese, Italian, Dutch, or a pair).

### Chunking for RAG

Chunks follow the document's headings, paragraphs and sentences, so a chunk rarely cuts a sentence in half. Set **Chunk size** in tokens (about 4 characters per token) and **Chunk overlap**. Each chunk carries the heading path above it, for example `Model Architecture > Attention`.

### Limits

- PDF and DOCX only (no .doc, images or spreadsheets). Up to 50 MB and 500 pages per PDF.
- Password-protected PDFs are skipped with a reason.
- OCR quality depends on the scan; handwriting is not supported.
- Multi-column PDFs are read line by line, so columns can interleave.
- A link that is not a PDF or DOCX, or a site that is down, is skipped: the run still ends SUCCEEDED, the file gets no row, the reason is in the status message and the `RUN_SUMMARY` record, and the file adds no charge. The run's start fee still applies, so a run where every file is skipped costs only the start fee.

### Engines and licences

Everything runs inside the Actor. No outside AI or OCR API is called.

| Part | Engine | Licence |
|---|---|---|
| PDF text and layout | pdfplumber, pdfminer.six | MIT |
| PDF page rendering for OCR | pypdfium2 (PDFium) | Apache-2.0 / BSD-3-Clause |
| OCR | Tesseract 5 with tessdata language models | Apache-2.0 |
| DOCX | mammoth + markdownify | BSD-2-Clause, MIT |

### FAQ

**Does it work on scanned PDFs?** Yes. Leave OCR on Auto and scanned pages are read with OCR.

**Can I convert only some pages?** Yes, set Page range, for example `1-5,8` or `10-last`.

**Why did a file give no row?** Open the run's status message or the `RUN_SUMMARY` record in the key-value store: it names each skipped URL and the reason (not a PDF/DOCX, HTTP error, source down, password-protected, no text).

**Can an AI agent call it?** Yes, through the Apify API or Apify's MCP server, with a list of URLs in `documentUrls`.

# Actor input Schema

## `documentUrls` (type: `array`):

Direct links to PDF or Word (.docx) files. Each file becomes one dataset row with its Markdown text. Up to 50 MB per file.

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

auto: OCR only pages with no text layer (scanned pages). always: OCR every page. off: never OCR.

## `ocrLanguage` (type: `string`):

Language of the scanned text. Combine with +, e.g. eng+fra.

## `pageRange` (type: `string`):

Only convert these pages, e.g. 1-5,8 or 10-last. Empty converts every page up to the page limit.

## `maxPagesPerDocument` (type: `integer`):

Stop after this many pages of each PDF (1 to 500).

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

Split the Markdown into retrieval chunks of about this many tokens (1 token = about 4 characters). Chunks respect headings, paragraphs and sentences. 0 turns chunking off.

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

Tokens repeated from the end of one chunk at the start of the next.

## `chunksAsRows` (type: `boolean`):

On: each chunk is its own dataset row (ready for a vector database). Off: one row per document with a chunks list.

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

Off leaves the markdown field empty and keeps only the chunks (smaller rows). Ignored when one row per chunk is on.

## Actor input object example

```json
{
  "documentUrls": [
    "https://arxiv.org/pdf/1706.03762",
    "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/skew.pdf"
  ],
  "ocrMode": "auto",
  "ocrLanguage": "eng",
  "maxPagesPerDocument": 200,
  "chunkSize": 400,
  "chunkOverlap": 40,
  "chunksAsRows": false,
  "includeMarkdown": true
}
```

# Actor output Schema

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

No description

## `markdown` (type: `string`):

No description

## `runSummary` (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 = {
    "documentUrls": [
        "https://arxiv.org/pdf/1706.03762",
        "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/skew.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("publicrecords/pdf-docx-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 = { "documentUrls": [
        "https://arxiv.org/pdf/1706.03762",
        "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/skew.pdf",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("publicrecords/pdf-docx-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 '{
  "documentUrls": [
    "https://arxiv.org/pdf/1706.03762",
    "https://raw.githubusercontent.com/ocrmypdf/OCRmyPDF/main/tests/resources/skew.pdf"
  ]
}' |
apify call publicrecords/pdf-docx-to-markdown --silent --output-dataset

```

## MCP server setup

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