# PDF to Text & Markdown for RAG - Page-Cited Chunks (`rinveta/pdf-to-markdown`) Actor

Convert PDF URLs to per-page text, Markdown and RAG-ready chunks with page numbers. Pay per page with a text layer; scanned pages are flagged, not billed.

- **URL**: https://apify.com/rinveta/pdf-to-markdown.md
- **Developed by:** [Rinveta](https://apify.com/rinveta) (community)
- **Categories:** AI, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.40 / 1,000 pages processed

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/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 for RAG – Page-Cited Chunks for LLMs

**Turn PDF files into clean per-page text, Markdown and RAG-ready chunks with page numbers.** Give it PDF URLs (or a dataset, or PDFs you stored in a key-value store) and get structured rows you can embed, index or feed to an LLM. Built for **RAG pipelines, document search, AI agents and data cleaning**.

No browser, no crawling: the Actor only downloads the PDF URLs **you provide** and reads their text layer. You pay **per page with extractable text**, so short documents cost very little.

### What can you do with it?

- **PDF to text, page by page:** one row per page with text, word count and character count.
- **PDF to Markdown:** headings and lists are detected from font sizes, wrapped lines are joined into paragraphs, hyphenated line breaks are repaired.
- **Chunk PDFs for RAG and LLMs:** configurable chunk size and overlap; every chunk keeps `pageStart` and `pageEnd`, so answers can cite the page.
- **Document metadata:** title, author, producer, creation date, PDF version, page count, file size and a SHA-256 of the file (useful to skip duplicates).
- **Detect scanned PDFs:** pages without a text layer are flagged `needsOcr` and are **not charged**. This version has no OCR.
- **Page ranges and safety limits:** `firstPage`, `lastPage`, `maxPagesPerPdf`, `maxPdfSizeMB`, `maxPdfs`.

### Use cases

- **Ingest reports, papers and manuals into a vector database:** use `outputMode: chunks` and send each row to your embedding step.
- **Build a knowledge base for an AI agent or chatbot** from public documents, whitepapers and policies you are allowed to use.
- **Extract the text of contracts, invoices or forms you own** to search, tag or summarize them.
- **Clean up a document archive:** one row per PDF (`outputMode: document`) with metadata and full text.
- **Pre-check a batch:** the run summary tells you how many PDFs were scanned and need OCR elsewhere.

### Input

| Field | Description |
|---|---|
| `pdfUrls` | Direct URLs of PDF files. |
| `inputDatasetId` + `datasetUrlField` | Alternative: a dataset (for example from another Actor) whose items contain a PDF URL. |
| `inputKeyValueStoreId` + `keyPrefix` | Alternative: PDFs you uploaded to a key-value store (keys ending in `.pdf`). |
| `outputMode` | `pages` (default), `chunks` (one row per RAG chunk) or `document` (one row per PDF). |
| `chunkSize`, `chunkOverlap` | Characters per chunk (default 1000, 0 disables) and overlap (default 100). |
| `includeMarkdown`, `includePlainText` | Choose which text fields you get (both on by default). |
| `firstPage`, `lastPage`, `maxPagesPerPdf` | Page range and a safety limit (default 300 pages per PDF). |
| `maxPdfSizeMB`, `maxPdfs`, `concurrency`, `downloadTimeoutSecs` | Limits (default 40 MB, 500 PDFs, 2 in parallel, 60 s). |

Example input:

```json
{
  "pdfUrls": [{ "url": "https://arxiv.org/pdf/1706.03762" }],
  "outputMode": "chunks",
  "chunkSize": 800,
  "chunkOverlap": 80
}
```

### Output

`outputMode: chunks` – one row per chunk:

```json
{
  "type": "chunk",
  "status": "ok",
  "sourceUrl": "https://arxiv.org/pdf/1810.04805",
  "documentTitle": null,
  "pageCount": 16,
  "chunkIndex": 12,
  "pageStart": 3,
  "pageEnd": 3,
  "charCount": 791,
  "text": "## 3 BERT\n\nWe introduce BERT and its detailed implementation in this section..."
}
```

`outputMode: pages` – one row per page (`pageNumber`, `pageCount`, `text`, `markdown`, `wordCount`, `charCount`, `needsOcr`, plus the chunks that start on that page). `outputMode: document` – one row per PDF with `text`, `markdown`, `chunks`, `metadata`, `likelyScanned`, `truncated`.

Failed files produce a row with `type: "error"` and a clear message (HTTP error, not a PDF, password-protected, too large) and are **not charged**. The key-value store contains `OUTPUT` with run totals: PDFs processed/failed, pages charged, pages without text, chunks.

### Pricing

Pay per event: **$0.0004 per page processed** (event `page-processed`, $0.40 per 1,000 pages). Only pages with an extractable text layer are charged; scanned pages, failed downloads and skipped files are free. A typical 15-page paper costs about $0.006.

### FAQ

**Does it do OCR?** Not in this version. Scanned PDFs are detected and flagged (`needsOcr`, `likelyScanned`) and are not charged.

**How are chunks built?** Along paragraph boundaries up to `chunkSize` characters, with `chunkOverlap` characters repeated. Each chunk records the first and last page it covers.

**Are tables extracted?** Table text appears in reading order as plain text; structured table output is not part of this version.

**Which PDFs work best?** PDFs with a real text layer: papers, reports, manuals, statements, forms. Complex multi-column layouts are returned in the order stored in the file.

**Password-protected files?** Not supported; they return an error row.

**Is the same PDF charged twice?** Every run is charged separately. Use the `sha256` in the metadata to skip files you already processed.

### Good to know

- Only the URLs you supply are downloaded; private/internal network addresses are refused.
- You are responsible for having the right to process the documents you submit.
- Memory: 512 MB is enough for typical PDFs; use 1–2 GB for very large files or higher concurrency.

### Recommended final step

For the cleanest data, use [**Dataset Merge, Dedupe & Transform**](https://apify.com/rinveta/dataset-merge-dedupe) as the final step of your pipeline: merge the datasets of several runs, remove duplicate chunks and export CSV, JSON or XLSX.

### Run locally / integrate

```bash
npm install
echo '{"pdfUrls":[{"url":"https://example.com/file.pdf"}]}' > storage/key_value_stores/default/INPUT.json
node src/main.js
```

Call it from the Apify API, the JavaScript/Python client, Make, Zapier, n8n or as a tool for AI agents (MCP).

### Related Actors

More Actors by Rinveta for data pipelines:

- [Image Compressor & Converter](https://apify.com/rinveta/image-converter): batch conversion and compression of images to WebP, AVIF, JPEG or PNG.
- [Dataset Merge, Dedupe & Transform](https://apify.com/rinveta/dataset-merge-dedupe): merge, deduplicate and convert datasets (CSV, JSON, XLSX).

**Related searches:** pdf to text, pdf to markdown, pdf extractor, pdf parser, pdf rag, pdf chunking, llm document ingestion, langchain pdf loader, vector database ingestion.

# Actor input Schema

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

Direct links to PDF files. Only the URLs you list here are downloaded.

## `inputDatasetId` (type: `string`):

ID or name of a dataset (for example the output of another Actor) whose items contain a PDF URL.

## `datasetUrlField` (type: `string`):

Name of the dataset field that contains the PDF URL.

## `inputKeyValueStoreId` (type: `string`):

ID or name of a key-value store holding your own PDF files. Every record whose key ends with .pdf is processed.

## `keyPrefix` (type: `string`):

Only process key-value store records whose key starts with this prefix.

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

pages: one row per page (default). chunks: one row per RAG chunk with page numbers, ready to embed. document: one row per PDF with the full text.

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

Target size of each chunk. Chunks follow paragraph boundaries and record the page range they cover. Set 0 to disable chunking.

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

Characters repeated at the start of the next chunk to keep context.

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

Add a Markdown version of each page (headings and lists detected from font sizes).

## `includePlainText` (type: `boolean`):

Add the plain text of each page.

## `firstPage` (type: `integer`):

First page to extract (1-based).

## `lastPage` (type: `integer`):

Last page to extract. 0 means until the end.

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

Safety limit: pages beyond this are skipped and the row is marked truncated.

## `maxPdfSizeMB` (type: `integer`):

Larger files are rejected before processing (no charge).

## `maxPdfs` (type: `integer`):

Stop after this many PDFs in one run (safety cap on cost and runtime).

## `concurrency` (type: `integer`):

How many PDFs are downloaded and parsed in parallel. Keep low for large documents (memory).

## `downloadTimeoutSecs` (type: `integer`):

Give up on a PDF URL if the download takes longer than this many seconds.

## Actor input object example

```json
{
  "pdfUrls": [
    {
      "url": "https://arxiv.org/pdf/1706.03762"
    }
  ],
  "datasetUrlField": "url",
  "outputMode": "pages",
  "chunkSize": 1000,
  "chunkOverlap": 100,
  "includeMarkdown": true,
  "includePlainText": true,
  "firstPage": 1,
  "lastPage": 0,
  "maxPagesPerPdf": 300,
  "maxPdfSizeMB": 40,
  "maxPdfs": 500,
  "concurrency": 2,
  "downloadTimeoutSecs": 60
}
```

# Actor output Schema

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

One row per page, chunk or PDF: text, Markdown, page numbers, metadata, scanned-PDF flags.

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

Totals: PDFs processed/failed, pages charged, pages without text, chunks.

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

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

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

```

## MCP server setup

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