# PDF to Markdown — LLM-Ready Text Extractor for RAG (`reverend_sal/pdf-to-markdown`) Actor

Convert PDF URLs to clean Markdown for LLMs and RAG: headings, paragraphs, lists, page numbers, metadata and token estimates. One item per PDF or per page. $0.0005 per page, scanned pages are free.

- **URL**: https://apify.com/reverend_sal/pdf-to-markdown.md
- **Developed by:** [North Eng](https://apify.com/reverend_sal) (community)
- **Categories:** AI, Developer tools
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.50 / 1,000 converted pdf pages

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 — LLM-ready text extractor for RAG

**PDF to Markdown** converts PDF files (by URL) into clean, structured Markdown that LLMs and RAG pipelines understand: headings detected from font sizes, paragraphs re-flowed, hyphenated line breaks fixed, bullet and numbered lists, page numbers removed, and optional `<!-- page N -->` markers so you can cite the source page.

It runs on a pure-JavaScript PDF engine (Mozilla pdf.js) — no browser, no OCR service, no API keys — so it is fast and cheap: a 15-page research paper converts in about 2 seconds.

### What it does

- **Structure, not just text**: `#`/`##`/`###` headings from font sizes, real paragraphs (wrapped lines joined), `- ` bullet lists and numbered lists.
- **Clean text**: de-hyphenation (`trans-` + `formers` → `transformers`, but `English-to-German` is kept), page numbers and rotated margin text (e.g. arXiv side stamps) removed, footnote markers kept with their words.
- **Page control**: convert only `1-3,7` with **Page range**, cap pages per PDF, and choose **one item per document** or **one item per page** (great for page-level citations in RAG).
- **Metadata**: file name and size, page count, title, author, subject, keywords, creator, producer, created/modified dates, word count and token estimate.
- **Works with share links**: Google Drive (`/file/d/…/view`) and Dropbox (`?dl=0`) links are turned into direct downloads automatically.
- **Honest about scans**: if a PDF has no text layer (scanned images), the item says `needsOcr: true` — and those pages are **not charged**.
- **Huge documents**: a 1,298-page government budget converts in under 30 seconds; documents too big for one dataset item get a 1M-character preview plus a link to the full Markdown file.

### Why use it

- **RAG / vector databases** — chunk research papers, manuals, contracts, reports and filings into a knowledge base.
- **LLM prompts** — Markdown keeps headings and lists, so models answer better than with raw `pdftotext` output, using fewer tokens.
- **Automations** — call it from Make, Zapier, n8n or the Apify API whenever a new PDF appears.

### How to use

1. Add one or more **PDF URLs** (direct links, Google Drive or Dropbox share links).
2. Optional: set a **Page range** or **Output** = one item per page.
3. Click **Start**. Each PDF's Markdown is in the `markdown` field; export as JSON, CSV or Excel, or fetch via the API.

### Input

| Field | Default | What it does |
|---|---|---|
| `urls` | "Attention Is All You Need" (arXiv) | PDF URLs to convert. |
| `outputMode` | `document` | `document` = one item per PDF. `page` = one item per page (with `pageNumber`). |
| `pageRange` | all pages | Pages to convert, e.g. `1-5`, `1,3,8-10`, `10-` (from 10 to the end). |
| `maxPagesPerPdf` | 500 | Safety cap on pages converted from each PDF (also caps cost). |
| `includePageMarkers` | true | Insert `<!-- page N -->` before each page in document mode. |
| `maxFileSizeMb` | 100 | Larger files are skipped with `TOO_LARGE` (not charged). |
| `timeoutSecs` | 120 | Download timeout per PDF. |
| `maxConcurrency` | 2 | PDFs processed in parallel. |

Example:

```json
{
  "urls": [
    { "url": "https://arxiv.org/pdf/1706.03762" },
    { "url": "https://www.irs.gov/pub/irs-pdf/fw9.pdf" }
  ],
  "pageRange": "1-5",
  "outputMode": "page"
}
```

### Output

Real example from the default input (Oct 22 2026, Markdown shortened):

```json
{
  "url": "https://arxiv.org/pdf/1706.03762",
  "finalUrl": "https://arxiv.org/pdf/1706.03762",
  "fileName": "1706.03762v7.pdf",
  "fileSizeBytes": 2215244,
  "numPages": 15,
  "pagesExtracted": 15,
  "pageNumbers": [
    1,
    2,
    3,
    "…",
    15
  ],
  "title": null,
  "author": null,
  "subject": null,
  "keywords": null,
  "creator": "LaTeX with hyperref",
  "producer": "pdfTeX-1.40.25",
  "createdAt": "2024-04-10T21:11:43.000Z",
  "modifiedAt": "2024-04-10T21:11:43.000Z",
  "markdown": "<!-- page 1 -->\n\nProvided proper attribution is provided, Google hereby grants permission to reproduce the tables and figures in this paper solely for use in journalistic or scholarly works.\n\n## Attention Is All You Need\n\n…\n\n### Abstract\n\nThe dominant sequence transduction models are based on complex recurrent or convolutional neural networks that include an encoder and a decoder.…",
  "charCount": 40075,
  "wordCount": 6496,
  "tokensEstimate": 10019,
  "needsOcr": false,
  "truncated": false,
  "error": null,
  "extractedAt": "2026-10-22T23:58:45.508Z"
}
```

In `page` mode each item has `pageNumber`, `markdown`, `charCount` and `wordCount` instead. If a document is too large for one dataset item (over ~8 MB of text), `markdown` holds the first 1,000,000 characters, `markdownIsPreview` is `true`, and `markdownFileUrl` links to the full `.md` file in the run's key-value store (`charCount` and `wordCount` always describe the full document).

Failed PDFs are listed with `error` and `errorCode` and are **not charged**:

```json
{
  "url": "https://example.com/",
  "error": "Not a PDF (content-type: text/html; charset=utf-8, 577 bytes). If this is a web page, use a web-page-to-Markdown Actor instead.",
  "errorCode": "NOT_A_PDF"
}
```

Error codes: `HTTP_404` (and other statuses), `NOT_A_PDF`, `ENCRYPTED` (password-protected), `INVALID_PDF`, `BAD_PAGE_RANGE`, `TOO_LARGE`, `TIMEOUT`, `NETWORK_ERROR`, `BLOCKED_URL` (the URL or a redirect resolves to a private, local or cloud-metadata address; such PDFs are never downloaded). A run summary is saved to the key-value store as `OUTPUT`.

### Pricing

Pay per page — you only pay for pages that actually contain text:

| Event | Price |
|---|---|
| Converted PDF page (pages with extractable text) | **$0.0005** ($0.50 per 1,000 pages) |
| Actor start | Apify default ($0.00005) |

Examples: a 15-page paper costs **$0.0075**; a 142-page IRS publication **$0.071**. Blank and scanned pages are free, failed downloads are free, and there is no per-file fee. Set a max cost per run to cap spending — the Actor stops converting when the budget is reached and keeps what it has done.

### FAQ

**Does it do OCR on scanned PDFs?**
No. It extracts the PDF's text layer. Scanned pages are flagged with `needsOcr: true` and cost nothing.

**Can it read password-protected PDFs?**
No — they are reported as `ENCRYPTED` and not charged.

**How accurate are tables?**
Table cells come out as text lines in reading order; complex multi-column tables are not rebuilt as Markdown tables. Headings, paragraphs and lists are reliable for typical reports, papers and manuals.

**Can I upload a file instead of a URL?**
Upload it anywhere that gives a public link (Google Drive, Dropbox, S3, the Apify key-value store) and paste that link.

### Limitations

- Text-based PDFs only (no OCR).
- Multi-column layouts are read in the PDF's content order, which is correct for most papers but can interleave columns in some magazine layouts.
- Only publicly downloadable URLs (no login-protected files).

# Actor input Schema

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

Direct links to PDF files (any public URL; Google Drive and Dropbox share links are converted to direct downloads). You can also upload a file in Apify and paste its URL here.

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

One dataset item per PDF (full Markdown document) or one item per page (best for RAG chunking and citations with page numbers).

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

Pages to extract, e.g. "1-5, 8, 10-". Leave empty for all pages.

## `maxPagesPerPdf` (type: `integer`):

Stop after this many pages of each PDF. You pay per page, so this also caps cost.

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

In one-item-per-PDF mode, put an HTML comment like  before each page so you can cite page numbers.

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

Larger files are skipped (not charged).

## `timeoutSecs` (type: `integer`):

Give up downloading a PDF after this long.

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

How many PDFs are downloaded and converted at the same time.

## Actor input object example

```json
{
  "urls": [
    {
      "url": "https://arxiv.org/pdf/1706.03762"
    }
  ],
  "outputMode": "document",
  "pageRange": "",
  "maxPagesPerPdf": 500,
  "includePageMarkers": true,
  "maxFileSizeMb": 100,
  "timeoutSecs": 120,
  "maxConcurrency": 2
}
```

# Actor output Schema

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

One item per PDF (or per page) with Markdown, metadata, word and token counts.

## `summary` (type: `string`):

PDFs converted, failed and pages charged.

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

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

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

```

## MCP server setup

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