# PDF to Markdown & RAG Chunks (`datacolada/pdf-to-markdown-rag`) Actor

Convert PDFs from URLs into clean, LLM-ready Markdown (headings, lists, paragraphs; headers, footers and page numbers removed) and optional RAG chunks with overlap, page numbers and heading context.

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

## Pricing

from $0.20 / 1,000 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 to Markdown & RAG Chunks

Turn PDFs into **clean, LLM-ready Markdown** and **ready-to-embed RAG chunks**: paste PDF links, get structured Markdown with headings, lists and paragraphs, with running headers, footers and page numbers removed. Each chunk comes with its page range and section path, so your answers can cite the right page.

No API keys, no OCR setup, no Python. Pages are processed in about a second per 50 pages.

### How to convert PDF to Markdown in 3 steps

1. Paste PDF links into **PDF URLs**.
2. Choose the output: full Markdown per document, RAG chunks, or both.
3. Click **Start**. Markdown and chunks appear in the **Output** tab, and each document is also saved as a `.md` file you can download.

### What it's for

- **RAG / vector databases**: feed chunks straight into Pinecone, Qdrant, Weaviate, pgvector, LangChain or LlamaIndex. Each chunk carries `headings` (the section path it sits under) and `pageStart`/`pageEnd` for citations.
- **LLM context**: give ChatGPT, Claude or your own agent a clean Markdown version of a paper, contract, manual, filing or report instead of a garbled copy-paste.
- **Knowledge bases**: convert policy documents, product manuals or research papers in bulk and store the `.md` files.
- **Automation**: call it from Make, Zapier, n8n or the Apify API whenever a new PDF shows up.

### What you get

| | |
|---|---|
| Headings | Detected from font size and bold text, mapped to `#`–`####`. Numbered sections (1, 1.1, 1.1.1) keep their numbers. |
| Paragraphs | Lines re-joined into real paragraphs, words split by line-end hyphens re-joined, ligatures (ﬁ, ﬂ) fixed. Two-column layouts are read column by column. |
| Lists | Bulleted and numbered lists become Markdown lists. |
| Noise removed | Running headers and footers (text repeated at the top or bottom of many pages), page numbers, "Page 3 of 40", rotated margin stamps. |
| Metadata | Title, author, subject, keywords, creator, producer, creation and modification dates, page count, word count, approximate token count. |
| Chunks | Section-aware chunks of your chosen size with overlap, page range and heading path. |

### Input

```json
{
  "pdfUrls": [
    "https://arxiv.org/pdf/1706.03762",
    "https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.100-1.pdf"
  ],
  "outputMode": "both",
  "chunkSize": 2000,
  "chunkOverlap": 200
}
```

| Field | Default | Notes |
|---|---|---|
| `pdfUrls` | – | Direct links to PDF files. Redirects are followed. |
| `outputMode` | `document` | `document` (one row per PDF), `chunks` (one row per chunk) or `both`. |
| `chunkSize` | 2000 | Max characters per chunk (≈ 500 tokens). 200–20,000. |
| `chunkOverlap` | 200 | Characters repeated from the previous chunk, cut at a sentence/word boundary. Not added across sections. |
| `maxPages` | 0 (all) | Convert only the first N pages of each PDF. |
| `removeHeadersFooters` | true | Remove running headers, footers and page numbers. |
| `includePageMarkers` | false | Insert `<!-- page N -->` comments. |
| `saveMarkdownFile` | true | Save each document as a `.md` file in the key-value store. |
| `maxFileSizeMb` | 50 | Larger files are skipped (not charged). Up to 200. |

**Your own files:** upload them to an Apify key-value store (or any file host, S3, Google Drive public link that serves the raw file) and paste the links.

### Output

#### Document row (`type: "document"`)

```json
{
  "type": "document",
  "url": "https://arxiv.org/pdf/1706.03762",
  "fileName": "1706.03762v7.pdf",
  "status": "ok",
  "title": "Attention Is All You Need",
  "author": null,
  "createdAt": "2024-04-10T21:11:43.000Z",
  "pageCount": 15,
  "pagesConverted": 15,
  "charCount": 38447,
  "wordCount": 5880,
  "approxTokens": 9612,
  "markdownUrl": "https://api.apify.com/v2/key-value-stores/…/records/1706.03762v7-dd93e904.md",
  "markdown": "…\n\n# Attention Is All You Need\n\n…\n\n## Abstract\n\nThe dominant sequence transduction models…",
  "chunkCount": 27
}
```

#### Chunk row (`type: "chunk"`)

```json
{
  "type": "chunk",
  "url": "https://arxiv.org/pdf/1706.03762",
  "title": "Attention Is All You Need",
  "chunkIndex": 7,
  "chunkCount": 27,
  "headings": ["Attention Is All You Need", "3 Model Architecture"],
  "pageStart": 4,
  "pageEnd": 4,
  "charCount": 1553,
  "approxTokens": 389,
  "text": "### 3.2.1 Scaled Dot-Product Attention\n\nWe call our particular attention \"Scaled Dot-Product Attention\"…"
}
```

Use the **Documents** and **Chunks** views in the dataset tab, or filter by `type` in the API. A `RUN_SUMMARY` record in the key-value store lists every PDF with its status.

#### Statuses

`ok` · `failed` (download error, HTTP 404 etc.) · `not-pdf` (the link returns a web page) · `too-large` · `encrypted` (password-protected) · `invalid-pdf` (corrupt file) · `no-text-layer` (scanned or image-only, OCR not supported yet) · `blocked` (private or internal address) · `skipped` (your max charge for the run was reached). **Only `ok` documents are charged.**

### Pricing

Pay per event, no subscription:

| Event | Price |
|---|---|
| PDF converted | $0.002 |
| Page converted | $0.0002 |

A 15-page paper costs **$0.005**. A 100-page report costs **$0.022**. 1,000 ten-page documents cost **$4**.

You are never charged for failed, blocked, password-protected, too-large or scanned PDFs. If you set a maximum charge for the run, the Actor stops cleanly at that limit: the last document may be truncated (`truncatedByChargeLimit: true`) and remaining documents are marked `skipped`.

### Integrations and API

- **Make, Zapier, n8n:** start the Actor when a new PDF link arrives (email, Drive, form) and send the Markdown or chunks to your vector database, Notion or Google Docs.
- **LangChain / LlamaIndex:** read the dataset with the Apify loaders, or with the API client below.
- **API / code:**

```bash
curl -X POST "https://api.apify.com/v2/acts/datacolada~pdf-to-markdown-rag/run-sync-get-dataset-items?token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"pdfUrls":["https://arxiv.org/pdf/1706.03762"],"outputMode":"chunks","chunkSize":2000}'
```

```python
from apify_client import ApifyClient
client = ApifyClient("YOUR_API_TOKEN")
run = client.actor("datacolada/pdf-to-markdown-rag").call(run_input={
    "pdfUrls": ["https://arxiv.org/pdf/1706.03762"],
    "outputMode": "chunks",
})
for chunk in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(chunk["pageStart"], " > ".join(chunk["headings"]), chunk["text"][:80])
```

### Tips

- For RAG, `chunkSize` 1500–3000 with `chunkOverlap` 150–300 works well for most embedding models.
- Prepend `headings.join(" > ")` to each chunk before embedding for better retrieval.
- Use `maxPages` to preview a large document cheaply.
- Very long documents: the full Markdown is always in the `.md` file (`markdownUrl`). Inline `markdown` is cut at 1.5M characters (`markdownTruncated: true`).

### Limitations

- Scanned PDFs (images without a text layer) are detected and skipped without charge; OCR is not included.
- Tables are output as text lines, not Markdown tables.
- Math formulas come out as their Unicode text, not LaTeX.
- Heading detection is based on fonts; unusual layouts (posters, slides, forms) may produce fewer headings.

### FAQ

**Does it work on scanned PDFs?** Not yet. PDFs without a text layer are detected, marked `no-text-layer` and not charged.

**Can I convert my own files?** Yes. Upload them to an Apify key-value store or any host that serves the raw PDF, and paste the links.

**What chunk size should I use?** 1,500 to 3,000 characters with 150 to 300 overlap suits most embedding models. Each chunk keeps its page range and section headings for citations.

**How much does it cost?** $0.002 per PDF plus $0.0002 per page converted. A 15-page paper costs $0.005. Failed, encrypted, scanned and too-large files are free.

**Are tables converted?** Tables come out as text lines, not Markdown tables, for now.

### Changelog

- **0.1.3**: README FAQ and API examples.
- **0.1**: first release.

# Actor input Schema

## `pdfUrls` (type: `array`):

Direct links to PDF files (http or https). To convert your own files, upload them to an Apify key-value store or any file host and paste the links.

## `outputMode` (type: `string`):

<b>document</b>: one row per PDF with the full Markdown. <b>chunks</b>: one row per RAG chunk. <b>both</b>: document rows and chunk rows.

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

Target maximum characters per chunk (about 4 characters per token). Chunks prefer to end at section and paragraph boundaries.

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

Characters from the end of the previous chunk repeated at the start of the next one (cut at a sentence or word boundary). Not added across new sections. Max: half the chunk size.

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

Convert only the first N pages of each PDF. 0 = all pages. You are charged only for pages converted.

## `removeHeadersFooters` (type: `boolean`):

Drops text repeated at the top or bottom of many pages (document titles, confidentiality notes) and bare page numbers.

## `includePageMarkers` (type: `boolean`):

Insert <code>\<!-- page N --></code> comments in the Markdown where each page starts.

## `saveMarkdownFile` (type: `boolean`):

Also store each document's Markdown as a file in the key-value store and link it from the dataset (handy for very long documents).

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

Larger files are skipped (not charged).

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

How many PDFs to download and convert at the same time.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://arxiv.org/pdf/1706.03762",
    "https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.100-1.pdf"
  ],
  "outputMode": "document",
  "chunkSize": 2000,
  "chunkOverlap": 200,
  "maxPages": 0,
  "removeHeadersFooters": true,
  "includePageMarkers": false,
  "saveMarkdownFile": true,
  "maxFileSizeMb": 50,
  "maxConcurrency": 3
}
```

# Actor output Schema

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

No description

## `files` (type: `string`):

No description

## `summary` (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 = {
    "pdfUrls": [
        "https://arxiv.org/pdf/1706.03762",
        "https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.100-1.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("datacolada/pdf-to-markdown-rag").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 = { "pdfUrls": [
        "https://arxiv.org/pdf/1706.03762",
        "https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.100-1.pdf",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("datacolada/pdf-to-markdown-rag").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 '{
  "pdfUrls": [
    "https://arxiv.org/pdf/1706.03762",
    "https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.100-1.pdf"
  ]
}' |
apify call datacolada/pdf-to-markdown-rag --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,datacolada/pdf-to-markdown-rag"
        }
    }
}
```

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/ju2kyftFWd6Og4bEC/builds/wKKa07GWlekHoGB6F/openapi.json
