# PDF to Text & Markdown Extractor for LLM & RAG (`adamplaenitz/pdf-text-extractor`) Actor

PDF to text and Markdown for LLMs and RAG: headings, lists, metadata, page ranges and ready chunks with page numbers. Input PDF URLs, arXiv/landing pages, web pages that link to PDFs, uploads, base64 or a key-value store. Password PDFs supported. Text layer only (no OCR).

- **URL**: https://apify.com/adamplaenitz/pdf-text-extractor.md
- **Developed by:** [Adam Plänitz](https://apify.com/adamplaenitz) (community)
- **Categories:** AI, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 pdf document 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/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 Text & Markdown Extractor for LLM & RAG

**Convert PDF to text and PDF to Markdown in bulk – a PDF parser and PDF text extractor built for LLMs, RAG pipelines and AI agents.** Paste PDF links, arXiv or journal landing pages, or a web page that links to PDFs; upload files, send base64 from an automation or pick an Apify key-value store. For every document you get clean **Markdown** (headings, paragraphs, lists), **plain text**, **metadata**, optional **one row per page** and **ready-to-embed chunks with page numbers**. Choose a **page range** and pay only for the pages you extract. Export as JSON, CSV or Excel, or call it from n8n, Make, Zapier, LangChain, the API or an MCP client.

Click **Start** without changing anything to try it on two public documents (NIST Cybersecurity Framework 2.0 and the Mistral 7B paper, 41 pages, about $0.025).

### What does it do?

1. **Collects the PDFs** from any mix of sources:
   - **PDF URLs** – direct links; redirects are followed.
   - **Landing pages** – if a URL returns a web page instead of a PDF (e.g. `https://arxiv.org/abs/2310.06825`), the Actor follows the PDF the page declares: the `citation_pdf_url` tag used by arXiv, journals and repositories, an embedded PDF viewer, or the only PDF link on the page.
   - **Web pages with PDF links** – e.g. a "Reports" or "Publications" page. The page is read once and up to *N* linked PDFs are processed (one level, no crawling).
   - **Uploads**, **base64** strings (for API calls and automations) and **records of a key-value store**.
2. **Reads the text layer** with [pdf.js](https://github.com/mozilla/pdf.js) (via [unpdf](https://github.com/unjs/unpdf)) – only the pages in your page range. Password-protected PDFs are opened with the password you enter.
3. **Rebuilds the structure:** fragments become lines and paragraphs; **headings** are detected from font size and font (`#`, `##`, `###`); bullet and numbered **lists** become Markdown lists; words hyphenated at line ends are joined; **running headers, footers and page numbers** that repeat on many pages are removed.
4. **Chunks** (optional): splits the Markdown into pieces of at most *N* characters with overlap, cut at paragraph, line or sentence boundaries. Each chunk carries its offset, **first and last page** and the nearest heading – metadata for your vector store and for citations.

Files that cannot be processed (download errors, non-PDFs, scanned PDFs without text, wrong password) get a **free** row with an error code.

### Who is it for?

- **RAG and chatbot builders** who need PDFs as Markdown chunks with page numbers in a vector database.
- **AI agent and LLM app developers** who want a model to read a PDF as compact text instead of a binary file – via API, MCP or LangChain.
- **Analysts, researchers and automation builders** (n8n, Make, Zapier) who extract text and metadata from many reports, papers or documents.

### Use cases

1. **RAG pipeline:** set *Chunk size* to e.g. 2000, run on your manuals, policies or standards and load `chunks` (text + `pageStart`/`pageEnd` + `heading`) straight into Pinecone, Qdrant, pgvector or a LangChain/LlamaIndex vector store. Answers can cite the page.
2. **Invoice and report processing:** send invoices or monthly reports as base64 or key-value store records from n8n/Make, use *Page range* `1-2` to read only the first pages, and pass the text to an LLM or your own parser for amounts, dates and totals.
3. **Searchable research PDFs:** paste arXiv abstract pages or a publications page of an institute; get title, dates and full Markdown for every paper, ready for full-text search, summaries or classification.

### Input

| Field | Default | Description |
|---|---|---|
| PDF URLs | two examples | Direct PDF links or landing pages, one per line. |
| Web pages with PDF links | – | Pages whose linked PDFs should be processed. |
| Maximum PDFs per web page | 20 | Limit per listed web page. |
| Upload PDF files | – | Upload from your computer (stored in your Apify storage). |
| Base64 PDFs (API) | – | `["JVBERi0x…"]` or `[{"fileName": "invoice.pdf", "data": "JVBERi0x…"}]`. |
| Key-value store with PDFs / Record keys | – | All records of a store, or only the listed keys. |
| PDF password | – | Used for PDFs that need a password to open (secret field). |
| Follow landing pages to their PDF | on | See above. |
| Output | Markdown and text | Markdown only, plain text only, or both. |
| One row per page | off | Extra rows (`itemType: "page"`) with page number and text. |
| Page range | all | e.g. `1-5, 8, 10-`. Only extracted pages are charged. |
| Maximum pages per document | 1000 | Safety limit. |
| Remove running headers and footers | on | Drops repeating top/bottom lines and page numbers. |
| Chunk size / Chunk overlap | 0 (off) / 200 | Characters per chunk and shared characters. |
| Maximum file size | 50 MB | Up to 200 MB with more memory. |
| Parallel documents, Download timeout, Respect robots.txt, Proxy | 3, 60 s, on, none | Download behaviour. |

The example URLs are the input default. If you send only uploads, base64 files, a key-value store or web pages (e.g. via API), the examples are skipped automatically, so you never pay for them by accident. The aliases `startUrls` (`[{ "url": "…" }]`) and `url` are accepted as well.

### Example input

```json
{
  "pdfUrls": [
    "https://arxiv.org/pdf/2310.06825v1",
    "https://arxiv.org/abs/2310.06825"
  ],
  "webPageUrls": ["https://www.example.org/annual-reports"],
  "maxPdfsPerWebPage": 10,
  "outputFormat": "both",
  "pageRange": "1-20",
  "chunkSize": 2000,
  "chunkOverlap": 200
}
```

### Example output

One row per document (shortened, from a real run on the Mistral 7B paper with chunk size 2000):

```json
{
  "itemType": "document",
  "source": "https://arxiv.org/pdf/2310.06825v1",
  "sourceType": "url",
  "fileName": "2310.06825v1.pdf",
  "contentType": "application/pdf",
  "fileSizeBytes": 3749788,
  "sha256": "dfbac4e7035344b305c947481f2e7e8a02f7a24a563917eb6e47f6591d14c5ae",
  "title": "Mistral 7B",
  "titleSource": "first-heading",
  "creationDate": "2023-10-11T00:48:17.000Z",
  "creator": "LaTeX with hyperref",
  "producer": "pdfTeX-1.40.25",
  "pdfVersion": "1.5",
  "pageCount": 9,
  "pagesExtracted": 9,
  "pageRange": "1-9",
  "pagesWithoutText": [],
  "wordCount": 3840,
  "charCount": 24970,
  "text": "Mistral 7B\n\n…",
  "markdown": "# Mistral 7B\n\n…\n\n## Abstract\n\nWe introduce Mistral 7B, a 7–billion-parameter language model engineered for superior performance and efficiency. …",
  "chunkCount": 16,
  "chunks": [
    { "index": 1, "text": "## Abstract\n\nWe introduce Mistral 7B, …", "charStart": 989, "charCount": 1728, "pageStart": 1, "pageEnd": 1, "heading": "Abstract" }
  ],
  "headersFootersRemoved": 8,
  "truncatedByMaxPages": false,
  "truncatedByCostLimit": false,
  "warning": null,
  "errorCode": null,
  "error": null
}
```

Rows from a landing page also contain `landingPageUrl`; rows from a web page contain `foundOnPage`. With *One row per page* you also get `{ "itemType": "page", "pageNumber": 3, "text": "…", "markdown": "…", "wordCount": 412, "hasText": true }`. The PDF's author field is deliberately not included.

Error codes include `HTTP_404`, `ENOTFOUND`, `ROBOTS_TXT`, `FILE_TOO_LARGE`, `NOT_A_PDF`, `WEB_PAGE_WITH_PDF_LINKS`, `NO_PDF_LINKS`, `INVALID_PDF`, `ENCRYPTED`, `WRONG_PASSWORD`, `NO_TEXT_LAYER`, `PAGE_RANGE_EMPTY`, `KVS_RECORD_NOT_FOUND`. Documents too large for one dataset item (about 9 MB of text) are stored in the run's key-value store and linked in `textRecordUrl`, `markdownRecordUrl` and `chunksRecordUrl`. The record `RUN-SUMMARY` holds counts and error codes.

### How much does it cost?

Pay per event – you only pay for what was extracted:

| Event | Price |
|---|---|
| Actor start | $0.00005 |
| Document processed | $0.002 |
| Page extracted | $0.0005 |

Failed downloads, non-PDF files, scanned PDFs without text, wrong passwords and web pages without PDF links are **free**. Page rows and chunks cost nothing extra. Platform usage is included.

**Examples**

- 1 PDF with 5 pages: $0.00005 + $0.002 + 5 × $0.0005 = **$0.0046**
- The two example documents (41 pages): $0.00005 + 2 × $0.002 + 41 × $0.0005 = **$0.0246**
- 1,000 one-page invoices: $0.00005 + $2.00 + $0.50 = **$2.50**
- 100 PDFs with 20 pages each: $0.00005 + $0.20 + 2,000 × $0.0005 = **$1.20**
- The same 100 PDFs, only pages `1-3`: $0.00005 + $0.20 + 300 × $0.0005 = **$0.35**

**Honest comparison:** other PDF text extractors in the Apify Store mostly charge a flat price per PDF regardless of its length (in November 2026 roughly $0.0018–$0.005 per PDF without OCR, see their pricing tabs). This Actor is **cheaper for short documents** (up to about 2–6 pages, depending on the competitor) and whenever you only need a page range, but **more expensive for long PDFs read in full** – a 20-page PDF costs $0.012 here. If you mostly convert long documents completely and do not need Markdown or chunks, a flat-price Actor will be cheaper.

You can set a maximum cost per run; the Actor stops cleanly when it is reached (the last document may be cut short – its row says so). Without browser or OCR, runs are fast: the two example documents take about 2 seconds of processing.

### Use with n8n, Make, Zapier, API, MCP and LangChain

The Actor ID is `adamplaenitz/pdf-text-extractor`.

- **n8n:** use the official [Apify node](https://docs.apify.com/platform/integrations/n8n) → *Run Actor and get dataset items*, paste the input JSON. Base64 from a previous node fits into `base64Pdfs`.
- **Make:** the official [Apify app](https://docs.apify.com/platform/integrations/make) → *Run an Actor* (synchronous) → *Get dataset items*.
- **Zapier:** the official [Apify integration](https://docs.apify.com/platform/integrations/zapier) → action *Run Actor*, then *Fetch dataset items*.
- **API** (one request, returns the rows):

```bash
curl -X POST "https://api.apify.com/v2/acts/adamplaenitz~pdf-text-extractor/run-sync-get-dataset-items?token=<YOUR_APIFY_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{"pdfUrls": ["https://arxiv.org/pdf/2310.06825v1"], "outputFormat": "markdown", "chunkSize": 2000}'
```

- **MCP (Claude, Cursor, other AI agents):** add the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp) with this Actor, e.g. `https://mcp.apify.com/?tools=adamplaenitz/pdf-text-extractor`. The agent can then read PDFs by URL.
- **LangChain** (Python, package `langchain-apify`):

```python
from langchain_apify import ApifyWrapper
from langchain_core.documents import Document

apify = ApifyWrapper()  # reads APIFY_API_TOKEN from the environment
loader = apify.call_actor(
    actor_id="adamplaenitz/pdf-text-extractor",
    run_input={"pdfUrls": ["https://arxiv.org/pdf/2310.06825v1"], "chunkSize": 2000},
    dataset_mapping_function=lambda item: Document(
        page_content=item.get("markdown") or item.get("text") or "",
        metadata={"source": item["source"], "title": item.get("title")},
    ),
)
docs = loader.load()
```

### FAQ

**Does it work with scanned PDFs?** Only PDFs with a text layer are read – there is no OCR. A scanned PDF without text gets a free `NO_TEXT_LAYER` row; partly scanned documents get a warning and the list `pagesWithoutText`. Run such files through an OCR tool first (many scanners and Acrobat can add a text layer), then use this Actor.

**Can I extract only some pages?** Yes – *Page range* such as `1-3, 10-`. Only those pages are read and charged; `pageCount` still shows the total.

**Can I give it a website instead of PDF links?** Put the page into *Web pages with PDF links*: the Actor reads that page once and processes up to *Maximum PDFs per web page* linked PDFs. Links created by JavaScript are not seen, and it does not crawl further pages.

**Are tables extracted?** Table text is kept in reading order, but as lines of text, not as structured cells or Markdown tables. Multi-column layouts follow the order stored in the PDF (usually correct).

**What about password-protected PDFs?** Enter the password in *PDF password*. Without it you get a free `ENCRYPTED` row, with a wrong one `WRONG_PASSWORD`. PDFs that only restrict printing or copying are read without a password.

### Data, rights and privacy

- **You are responsible for having the right to process the documents you submit** (copyright, licences, confidentiality, personal data). The Actor only processes the files and pages you provide, respects robots.txt by default and refuses private or internal addresses.
- The example documents are freely available: the NIST Cybersecurity Framework 2.0 is a work of the U.S. government; the Mistral 7B paper is published on arXiv under CC BY 4.0 (Jiang et al., arXiv:2310.06825).
- Uploaded files stay in your own Apify storage. Open-source components: pdf.js (Apache-2.0) via unpdf (MIT), robots-parser (MIT), got-scraping (Apache-2.0). Not affiliated with Mozilla, NIST, arXiv or any publisher.

Questions or feature requests? Please open an issue in the **Issues** tab.

# Actor input Schema

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

Links to PDF files, one per line (e.g. https://arxiv.org/pdf/2310.06825v1). Landing pages such as an arXiv abstract or a journal article page also work: their main PDF is followed automatically. Duplicates are removed; files that cannot be downloaded or are not PDFs produce a free error row. The two example documents (NIST CSF 2.0 and the Mistral 7B paper, 41 pages) are used when you start without changes; they are skipped automatically if you only give uploads, base64 files, a key-value store or web pages.

## `webPageUrls` (type: `array`):

Optional. Web pages that link to PDF files (e.g. a reports, publications or downloads page), one per line. Every listed page is read once and the PDFs it links to are processed like PDF URLs (no crawling of further pages). Pages that cannot be read or contain no PDF links produce a free row.

## `maxPdfsPerWebPage` (type: `integer`):

At most this many PDF links are taken from each web page above (in page order).

## `uploadedFiles` (type: `array`):

Optional. Upload PDF files from your computer; they are stored in Apify storage and read from there. You can also paste Apify key-value store record URLs here.

## `base64Pdfs` (type: `array`):

Optional, mainly for API calls and automations (n8n, Make, Zapier): PDFs as base64 strings (a data:application/pdf;base64, prefix is allowed) or objects {"fileName": "invoice.pdf", "data": "<base64>"}. Keep the whole input below a few MB; for bigger files use URLs or a key-value store.

## `keyValueStore` (type: `string`):

Optional. Select one of your Apify key-value stores that contains PDF files. All its records are processed (records that are not PDFs get a free error row), or only the record keys listed below.

## `recordKeys` (type: `array`):

Optional. Only these records of the selected key-value store, one key per line (e.g. annual-report-2024). Empty = all records (up to 10,000).

## `pdfPassword` (type: `string`):

Optional. Password for protected PDFs that cannot be opened without one; it is tried on every protected file of the run. PDFs that only restrict printing or copying need no password. Stored encrypted by Apify.

## `followLandingPages` (type: `boolean`):

If a PDF URL returns a web page instead of a PDF, follow the PDF that the page declares (citation_pdf_url meta tag as on arXiv and journal sites, an embedded PDF viewer, or the only PDF link on the page).

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

Markdown: headings (detected from font size and font), paragraphs and lists – best for LLMs and chunking. Text: plain text with paragraphs separated by blank lines. Both: both fields.

## `pageRows` (type: `boolean`):

Additionally store one dataset row per extracted page (itemType "page", with page number, text and/or Markdown) – handy for citations with page numbers. No extra cost: pages are charged once either way.

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

Optional. Pages to extract, 1-based, e.g. "1-5, 8, 10-" (open end = up to the last page). Empty = all pages. Only extracted pages are charged – e.g. "1-3" reads just the first pages of long reports at a fraction of the cost.

## `maxPagesPerDocument` (type: `integer`):

Safety limit: at most this many of the selected pages are extracted per document (the rest is skipped and not charged; the row gets a warning).

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

Remove lines at the top or bottom of pages that repeat on at least half of the pages (running titles, footers) and lone page numbers – less noise for embeddings.

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

Optional. If set (e.g. 2000), the Markdown (or the text in text-only mode) is also split into chunks of at most this many characters, preferably at paragraph, line or sentence boundaries. Each chunk carries its first and last page number and the nearest heading. 0 = no chunking.

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

How many characters consecutive chunks share (at most half the chunk size). Only used when a chunk size is set.

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

Larger files are aborted during the download and reported as a free error row. For files above 100 MB give the run more memory (e.g. 4 GB).

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

How many PDFs are downloaded and parsed at the same time (1–10). Requests to the same host are additionally spaced by 0.5 seconds.

## `requestTimeoutSecs` (type: `integer`):

A download is aborted if the server sends no data for this many seconds (free error row).

## `respectRobotsTxt` (type: `boolean`):

Skip URLs that the robots.txt of the site disallows for crawlers (free error row). Switch off only for sites you own or may access.

## `proxyConfiguration` (type: `object`):

Optional. Only needed if a server blocks downloads from cloud servers.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://nvlpubs.nist.gov/nistpubs/CSWP/NIST.CSWP.29.pdf",
    "https://arxiv.org/pdf/2310.06825v1"
  ],
  "maxPdfsPerWebPage": 20,
  "followLandingPages": true,
  "outputFormat": "both",
  "pageRows": false,
  "maxPagesPerDocument": 1000,
  "removeHeadersFooters": true,
  "chunkSize": 0,
  "chunkOverlap": 200,
  "maxFileSizeMb": 50,
  "maxConcurrency": 3,
  "requestTimeoutSecs": 60,
  "respectRobotsTxt": true,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

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

One item per PDF with metadata, text and/or Markdown and optional chunks (plus optional page rows and free rows for files or web pages that could not be processed).

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

Counts of extracted documents and pages, failed files and error codes.

# 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://nvlpubs.nist.gov/nistpubs/CSWP/NIST.CSWP.29.pdf",
        "https://arxiv.org/pdf/2310.06825v1"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("adamplaenitz/pdf-text-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 = { "pdfUrls": [
        "https://nvlpubs.nist.gov/nistpubs/CSWP/NIST.CSWP.29.pdf",
        "https://arxiv.org/pdf/2310.06825v1",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("adamplaenitz/pdf-text-extractor").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://nvlpubs.nist.gov/nistpubs/CSWP/NIST.CSWP.29.pdf",
    "https://arxiv.org/pdf/2310.06825v1"
  ]
}' |
apify call adamplaenitz/pdf-text-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,adamplaenitz/pdf-text-extractor"
        }
    }
}
```

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/3q9VBXl9lkHDRWDu6/builds/c6glhbbHc7oINEHjG/openapi.json
