# PDF to Markdown & JSON (RAG-Ready) (`basisweb/pdf-to-markdown-rag`) Actor

Convert PDFs to clean Markdown and structured JSON (text + tables) for RAG, LLMs, and vector DBs. Batch URLs, pay per page.

- **URL**: https://apify.com/basisweb/pdf-to-markdown-rag.md
- **Developed by:** [BasisWeb](https://apify.com/basisweb) (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 $2.00 / 1,000 page processeds

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## PDF to Markdown & JSON (RAG-Ready)

Convert PDFs into clean **Markdown** and structured **JSON** (text + tables) you can drop straight into a RAG pipeline, an LLM prompt, or a vector database. Give it a list of PDF URLs; it returns one record per page.

Think of it as the **PDF companion to web crawlers** like [Website Content Crawler](https://apify.com/apify/website-content-crawler) and [RAG Web Browser](https://apify.com/apify/rag-web-browser): point it at the PDFs your crawler discovers and get clean, page-level text + tables back.

### What it does

- Downloads each PDF by URL.
- Extracts text using the PDF's character layout (natural reading order for standard single-column pages) and detects tables, rendering them as Markdown tables **and** structured rows.
- Returns **one dataset item per page**. `url`, `page`, `totalPages`, `tableCount`, and `ok` are always present; `markdown` and/or `text` + `tables` are included depending on `outputFormat` (default `both` returns all of them).

### Use cases

- **RAG ingestion**: turn reports, manuals, and whitepapers into clean, page-level Markdown chunks for a vector database.
- **LLM document Q\&A**: feed structured text and tables to an LLM without copy-paste cleanup.
- **Extract tables from PDF**: pull tables out as both Markdown and structured rows.
- **Agent pipelines**: chain it after a web crawler so an AI agent can read the PDFs it finds.

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `pdfUrls` | array of URLs | *(required)* | Direct links to the PDFs to convert. |
| `extractTables` | boolean | `true` | Detect tables and render them as Markdown + structured rows. |
| `outputFormat` | `markdown` | `json` | `both` | `both` | What each result includes. |

#### Example input

```json
{
  "pdfUrls": ["https://example.com/report.pdf"],
  "extractTables": true,
  "outputFormat": "both"
}
```

#### Example output (one item per page)

```json
{
  "url": "https://example.com/report.pdf",
  "page": 1,
  "totalPages": 12,
  "markdown": "Q3 Report\nRevenue grew 18% YoY...\n\n| Region | Revenue |\n| --- | --- |\n| NA | $4.1M |",
  "text": "Q3 Report\nRevenue grew 18% YoY...",
  "tables": [[["Region", "Revenue"], ["NA", "$4.1M"]]],
  "tableCount": 1,
  "ok": true
}
```

The example above uses the default `outputFormat: "both"`, so it includes every field. Each item also includes `ok` (set to `false` on a failed URL or page, with an `error` field explaining why) and, on pages with no extractable text or tables, a `note` flag.

### Pricing (pay-per-event)

- **Run start**: a small flat fee per run (Apify's built-in start event).
- **Page processed**: charged per page that returns real content (text and/or tables).

**Pages with no extractable text or tables are returned with a `note` and are NOT charged.** Failed URLs and failed pages are reported with an error and are never charged.

Your spending limit is always respected: set a max cost per run and the Actor stops once it's reached.

### Use it with AI agents (Apify MCP)

This Actor is available as a tool for AI agents through Apify's MCP server (`mcp.apify.com`). An agent can call `basisweb/pdf-to-markdown-rag` to convert a PDF to Markdown mid-task, then chain the page-level output into the next step. The only required input is `pdfUrls`, so an agent can invoke it in one shot, and the output schema tells the agent exactly which fields come back (`markdown`, `text`, `tables`, `tableCount`) before it spends a credit.

### Honest notes

- This handles **digital, text-based PDFs**. **Scanned PDFs** (image-only, no text layer) are not OCR'd in this version; those pages come back with a `note` instead of text and are **not charged**. OCR is planned for a future version.
- Each PDF must be under **50 MB**. Very large or table-heavy PDFs run best at 2 GB memory or higher (the 50 MB limit caps file size, not parsing memory).
- You can also parse PDFs locally for free with open-source libraries. This is the **no-setup, hosted, pay-per-page** version for pipelines that just want it as an API.

### FAQ

**Does it work on scanned PDFs?** Not in this version. Image-only pages with no text layer come back with a `note` and are not charged. OCR is planned for a future version.

**What does it return per page?** One item per page with `markdown` and/or `text` + `tables` (depending on `outputFormat`), plus `url`, `page`, `totalPages`, and `tableCount`.

**How is it priced?** A small per-run start fee plus a per-page fee, charged only for pages with real content. Blank, scanned, and failed pages are never charged.

**Can I use it for RAG?** Yes, that is the point. The Markdown is clean and page-scoped, so you can chunk and embed it directly.

**How is this different from parsing PDFs locally?** You can parse PDFs locally for free with open-source libraries. This is the no-setup, hosted, pay-per-page version for pipelines that just want it as an API.

### Run locally

```bash
apify run
```

### Deploy

```bash
apify login
apify push
```

# Actor input Schema

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

Direct URLs to the PDF files you want to convert. Each PDF is processed page by page.

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

Detect tables on each page and render them as Markdown tables plus structured rows. Turn off for faster text-only extraction.

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

What to include in each result: clean Markdown, structured JSON (raw text + tables), or both.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "extractTables": true,
  "outputFormat": "both"
}
```

# 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 = {
    "pdfUrls": [
        "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("basisweb/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://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"] }

# Run the Actor and wait for it to finish
run = client.actor("basisweb/pdf-to-markdown-rag").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).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://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ]
}' |
apify call basisweb/pdf-to-markdown-rag --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=basisweb/pdf-to-markdown-rag",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/5bb76xRxsaSMKjjTg/builds/O5gfmqJXeThnbFsyb/openapi.json
