# PDF Extractor: PDF → Clean Markdown + JSON for LLM/RAG (`boxbox10/pdf-extractor`) Actor

Turn any PDF URL into clean, LLM-ready Markdown + structured JSON (title, metadata, per-page text, page count, word count, token count). Perfect for RAG pipelines, AI agents, and LLM document ingestion.

- **URL**: https://apify.com/boxbox10/pdf-extractor.md
- **Developed by:** [Marvin Eguilos](https://apify.com/boxbox10) (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 $3.00 / 1,000 results

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 a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js/docs.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python/docs.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/integrations/mcp.md).

If your project is in a different language, use 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 Extractor — PDF → Clean Markdown + JSON for LLM & RAG

**Give it a PDF URL. Get back clean, LLM-ready Markdown and structured JSON.** Title, metadata, per-page text, page count, word count, and an accurate token count — every document, one tidy result. Built for RAG pipelines, AI agents, and anyone who needs the *text* of a PDF without wrestling with binary parsing, broken encodings, or page-layout noise.

> Feed your PDFs to your LLM the way it wants to be fed: as clean Markdown, chunkable by page, with the token budget already counted.

---

### ✨ What it does

- **Robust PDF text extraction** — powered by Mozilla's `pdf.js` (via `unpdf`), the same battle-tested engine that renders PDFs in Firefox. Handles multi-page documents, embedded fonts, and complex layouts.
- **Clean Markdown** — normalized whitespace, collapsed noise, optional per-page separators (`--- Page N ---`) so you can chunk on natural document boundaries.
- **Structured JSON** — `title`, `metadata` (author, subject, keywords, creator, producer, creation/modification dates, PDF version), `pageCount`, `pages[]` (per-page text), `wordCount`, `tokenCount`, `fileSizeBytes`, `fetchedAt`.
- **Accurate token counts** — counted with the GPT/`cl100k`-family tokenizer so you know exactly how much context each PDF costs *before* you send it to a model.
- **Token budgeting** — optional `maxTokens` truncates output to fit your context window.
- **Page-level chunking** — the `pages[]` array gives you clean text per page, ideal for granular RAG retrieval and citations.
- **Robust by design** — one bad URL never kills the run. Failed downloads/parses return a clean error record (and are **never charged**).
- **Safe & efficient** — file-size guard, `%PDF-` magic-byte validation, and content-type checks reject non-PDFs before wasting compute.

---

### 🎯 Use cases

| You want to… | This Actor gives you… |
|---|---|
| **Build a RAG knowledge base from PDFs** | Clean Markdown + per-page text with token counts, ready to embed. |
| **Ingest research papers (arXiv, journals)** | Structured text + metadata your pipeline can index and cite. |
| **Feed reports / whitepapers to an LLM** | Pre-counted tokens so you never blow the context window. |
| **Give an AI agent document context** | Structured JSON your agent can reason over — no binary noise. |
| **Convert PDF docs to Markdown** | Portable, diff-friendly Markdown you can drop into a repo or wiki. |
| **Chunk documents by page for citations** | A `pages[]` array with clean text and page numbers. |

---

### 📥 Input

| Field | Type | Default | Description |
|---|---|---|---|
| `urls` | string[] | — **(required)** | One or more direct links to PDF files. Each successful PDF is one result. |
| `outputFormat` | `both` \| `markdown` \| `json` | `both` | Include Markdown, the JSON fields, or both. |
| `includePageText` | boolean | `true` | Include a `pages[]` array with per-page text in the JSON output. |
| `pageSeparators` | boolean | `true` | Insert `--- Page N ---` markers between pages in the Markdown. |
| `maxPagesPerRun` | integer | `1000` | Safety cap on PDF URLs processed per run. |
| `maxTokens` | integer | `0` | Truncate Markdown to ~N tokens (`0` = no limit). |
| `maxFileSizeMb` | integer | `100` | Skip PDFs larger than this size (recorded as failures, never charged). |

#### Example input

```json
{
  "urls": [
    "https://arxiv.org/pdf/1706.03762",
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "outputFormat": "both",
  "includePageText": true,
  "pageSeparators": true,
  "maxTokens": 0
}
````

***

### 📤 Output

One dataset item per PDF. Successful example (truncated):

```json
{
  "url": "https://arxiv.org/pdf/1706.03762",
  "finalUrl": "https://arxiv.org/pdf/1706.03762",
  "statusCode": 200,
  "title": "Attention Is All You Need",
  "metadata": {
    "title": "Attention Is All You Need",
    "author": "Ashish Vaswani et al.",
    "creator": "LaTeX with hyperref",
    "producer": "pdfTeX",
    "creationDate": "D:20170612...",
    "pdfVersion": "1.5"
  },
  "pageCount": 15,
  "fileSizeBytes": 2215244,
  "wordCount": 8823,
  "tokenCount": 13140,
  "fetchedAt": "2026-07-19T02:17:19.954Z",
  "markdown": "Attention Is All You Need\n\n...\n\n---\n\n**Page 2**\n\n...",
  "pages": [
    { "page": 1, "text": "Attention Is All You Need\n\n..." }
  ]
}
```

Failed URL (returned to a separate `failures` dataset, **not charged**):

```json
{
  "url": "https://not-a-real-domain-xyz.com/file.pdf",
  "finalUrl": "https://not-a-real-domain-xyz.com/file.pdf",
  "statusCode": null,
  "error": "getaddrinfo ENOTFOUND not-a-real-domain-xyz.com",
  "fetchedAt": "2026-07-19T02:17:19.831Z"
}
```

***

### 🔌 Call it from code (Apify API)

```bash
curl -X POST "https://api.apify.com/v2/acts/YOUR_USERNAME~pdf-extractor/run-sync-get-dataset-items?token=YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"urls":["https://arxiv.org/pdf/1706.03762"]}'
```

```javascript
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: 'YOUR_TOKEN' });
const { defaultDatasetId } = await client
    .actor('YOUR_USERNAME/pdf-extractor')
    .call({ urls: ['https://arxiv.org/pdf/1706.03762'] });
const { items } = await client.dataset(defaultDatasetId).listItems();
console.log(items[0].markdown);
```

***

### 💸 Pricing (Pay-Per-Event)

| Event | Price |
|---|---|
| Actor start | **$0.05** per run |
| Extracted PDF | **$0.003** per successfully extracted PDF |

- **You only pay for PDFs that succeed** — failed URLs are never charged.
- **🎁 Free tier:** free-plan users' platform usage is covered by Apify, so you can try it and run small jobs at **no cost** before scaling up.
- Structured per-page JSON + accurate token counts, purpose-built for LLM/RAG ingestion — at a low, predictable price point.

***

### ⚖️ Acceptable use

This is a general-purpose format-conversion tool: **you supply the PDF URLs and are responsible for having the right to download and use the content you submit.** The Actor identifies itself with a descriptive User-Agent and only extracts text from documents you point it at. It does not target any single platform's private API and does not harvest personal data as a feature. Please comply with each source's terms of service and applicable law.

***

### 🧱 Under the hood

Node.js · [unpdf](https://github.com/unjs/unpdf) (Mozilla `pdf.js` core, serverless-friendly) · [gpt-tokenizer](https://github.com/niieani/gpt-tokenizer) · Apify SDK. Pure-JS extraction — no headless browser, no system libraries. Stateless — nothing is stored between runs.

# Actor input Schema

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

One or more direct links to PDF files. Each successfully extracted PDF is one billable result.

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

What to include per result: Markdown only, JSON fields only, or both.

## `includePageText` (type: `boolean`):

Include a structured `pages[]` array with the raw text of each page in the JSON output. Useful for page-level chunking in RAG.

## `pageSeparators` (type: `boolean`):

Insert a horizontal-rule page marker (e.g. '--- Page 2 ---') between pages in the Markdown output.

## `maxPagesPerRun` (type: `integer`):

Safety cap on how many PDF URLs are processed in a single run.

## `maxTokens` (type: `integer`):

Optional. Truncate the Markdown output to approximately this many tokens (0 = no limit). Useful for fitting LLM context windows.

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

Skip PDFs larger than this size (in megabytes) to protect compute. Oversized files are recorded as failures and never charged.

## Actor input object example

```json
{
  "urls": [
    "https://arxiv.org/pdf/1706.03762"
  ],
  "outputFormat": "both",
  "includePageText": true,
  "pageSeparators": true,
  "maxPagesPerRun": 1000,
  "maxTokens": 0,
  "maxFileSizeMb": 100
}
```

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

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

# Run the Actor and wait for it to finish
run = client.actor("boxbox10/pdf-extractor").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 '{
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
    "https://arxiv.org/pdf/1706.03762"
  ]
}' |
apify call boxbox10/pdf-extractor --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "PDF Extractor: PDF → Clean Markdown + JSON for LLM/RAG",
        "description": "Turn any PDF URL into clean, LLM-ready Markdown + structured JSON (title, metadata, per-page text, page count, word count, token count). Perfect for RAG pipelines, AI agents, and LLM document ingestion.",
        "version": "0.1",
        "x-build-id": "smDCjQhX0hUciwhD6"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/boxbox10~pdf-extractor/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-boxbox10-pdf-extractor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/boxbox10~pdf-extractor/runs": {
            "post": {
                "operationId": "runs-sync-boxbox10-pdf-extractor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/boxbox10~pdf-extractor/run-sync": {
            "post": {
                "operationId": "run-sync-boxbox10-pdf-extractor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "urls"
                ],
                "properties": {
                    "urls": {
                        "title": "PDF URLs",
                        "type": "array",
                        "description": "One or more direct links to PDF files. Each successfully extracted PDF is one billable result.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "outputFormat": {
                        "title": "Output format",
                        "enum": [
                            "both",
                            "markdown",
                            "json"
                        ],
                        "type": "string",
                        "description": "What to include per result: Markdown only, JSON fields only, or both.",
                        "default": "both"
                    },
                    "includePageText": {
                        "title": "Include per-page text array",
                        "type": "boolean",
                        "description": "Include a structured `pages[]` array with the raw text of each page in the JSON output. Useful for page-level chunking in RAG.",
                        "default": true
                    },
                    "pageSeparators": {
                        "title": "Page separators in Markdown",
                        "type": "boolean",
                        "description": "Insert a horizontal-rule page marker (e.g. '--- Page 2 ---') between pages in the Markdown output.",
                        "default": true
                    },
                    "maxPagesPerRun": {
                        "title": "Max PDFs per run",
                        "minimum": 1,
                        "maximum": 100000,
                        "type": "integer",
                        "description": "Safety cap on how many PDF URLs are processed in a single run.",
                        "default": 1000
                    },
                    "maxTokens": {
                        "title": "Max tokens per result",
                        "minimum": 0,
                        "maximum": 2000000,
                        "type": "integer",
                        "description": "Optional. Truncate the Markdown output to approximately this many tokens (0 = no limit). Useful for fitting LLM context windows.",
                        "default": 0
                    },
                    "maxFileSizeMb": {
                        "title": "Max PDF file size (MB)",
                        "minimum": 1,
                        "maximum": 2000,
                        "type": "integer",
                        "description": "Skip PDFs larger than this size (in megabytes) to protect compute. Oversized files are recorded as failures and never charged.",
                        "default": 100
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
