# PDF to Text & Markdown Extractor for LLMs | $3/1K (`rasareka/pdf-text-extractor`) Actor

Extract clean text and Markdown from PDF URLs for LLM, RAG and search pipelines. Split by document, page or overlapping chunks. Get title, author, dates, page count, word count, language and scanned-page detection. Pure JS, no OCR, no API key.

- **URL**: https://apify.com/rasareka/pdf-text-extractor.md
- **Developed by:** [Rasa Reka](https://apify.com/rasareka) (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 $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/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 LLMs

Turn **PDF links into clean text and Markdown** for LLM prompts, **RAG pipelines**, vector databases and search indexes. Paste PDF URLs and get one item per document, per page, or **overlapping chunks ready for embeddings**, plus the PDF's title, author, dates, page count, word count and a scanned-page warning.

### What you get

- 📝 **Plain text** with paragraphs kept as blank-line separated blocks
- \#️⃣ **Markdown**: headings detected from font size (and numbered section titles like "3.1 Attention"), paragraphs joined into single lines, hyphenated line breaks fixed ("transfor-mer" → "transformer"), page numbers removed
- ✂️ **Three ways to split**: whole document, one item per page, or RAG chunks (default 4,000 characters with 200 overlap) with `pageStart` / `pageEnd` for citations
- 🏷️ **PDF metadata**: title, author, subject, keywords, creator, producer, creation and modification date
- 🔢 `pageCount`, `charCount`, `wordCount` and a simple `language` guess
- 🖼️ **`isScanned` flag** for pages with almost no text (probably image-only), so you know which files need OCR
- 🆓 Failed URLs (not a PDF, password-protected, too large, 403/404) are listed in a `FAILED` record and **not charged**

### Why this Actor

| | This Actor |
|---|---|
| Input | Direct PDF URLs (arXiv, company reports, government PDFs, any public link) |
| Output | Text, Markdown, or both |
| Split by | Document, page, or overlapping chunks |
| Page numbers for chunks | Yes (`pageStart`, `pageEnd`) |
| Scanned PDF detection | Yes (`isScanned`, `scannedPages`) |
| Failed files | Free, listed separately |
| Login / API key / proxies | Not needed |
| Engine | Mozilla pdf.js (pure JavaScript), no OCR |

### Use cases

- **RAG / LLM ingestion:** chunk PDFs into ~1,000-token pieces with overlap and page references, then send them straight to your embeddings model or vector DB (Pinecone, Qdrant, Weaviate, pgvector...)
- **Research papers:** pull arXiv and journal PDFs into Markdown for summarising, literature reviews or building a paper Q\&A bot
- **Invoices, annual reports and statements:** get the text out of digital (not scanned) PDFs for parsing, keyword checks or feeding an LLM extractor
- **Search indexing:** index PDF content per page so search results can link to the right page

### Input example

```json
{
  "pdfUrls": [
    "https://arxiv.org/pdf/1706.03762",
    "https://arxiv.org/pdf/1810.04805"
  ],
  "outputFormat": "both",
  "splitBy": "chunk",
  "chunkSize": 4000,
  "chunkOverlap": 200,
  "maxPages": 0,
  "includeMetadata": true,
  "maxFileSizeMb": 50
}
```

| Field | Default | Meaning |
|---|---|---|
| `pdfUrls` | – | Direct links to PDF files |
| `outputFormat` | `both` | `text`, `markdown` or `both` |
| `splitBy` | `document` | `document` (1 item per PDF), `page` (1 item per page), `chunk` (RAG chunks) |
| `chunkSize` | `4000` | Target characters per chunk (cut at paragraph / sentence / word boundaries) |
| `chunkOverlap` | `200` | Characters repeated from the previous chunk |
| `maxPages` | `0` | Read only the first N pages (0 = all) |
| `includeMetadata` | `true` | Add PDF document info fields |
| `maxFileSizeMb` | `50` | Skip larger files (free) |

With empty input the Actor runs a small sample: the first 3 pages of *Attention Is All You Need*.

### Output example

Real output from a test run (`splitBy: document`, first 3 pages of arXiv 1706.03762). Long text is trimmed here with "...".

```json
{
  "url": "https://arxiv.org/pdf/1706.03762",
  "fileName": "1706.03762v7.pdf",
  "pageCount": 15,
  "pagesExtracted": 3,
  "title": null,
  "author": null,
  "subject": null,
  "keywords": null,
  "creator": "LaTeX with hyperref",
  "producer": "pdfTeX-1.40.25",
  "creationDate": "2024-04-10T21:11:43.000Z",
  "modDate": "2024-04-10T21:11:43.000Z",
  "language": "en",
  "text": "Provided proper attribution is provided, Google hereby grants permission to\nreproduce the tables and figures in this paper solely for use in journalistic or\nscholarly works.\n\nAttention Is All You Need\n\n...",
  "markdown": "Provided 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. ...\n\n## 1 Introduction\n\n...\n\n### 3.1 Encoder and Decoder Stacks\n\n...",
  "charCount": 8982,
  "wordCount": 1308,
  "isScanned": false,
  "scannedPages": []
}
```

(`title` and `author` are `null` here because this PDF leaves them empty in its document info. Many PDFs do.)

A chunk item (`splitBy: chunk`) has the same document fields plus:

```json
{
  "chunkIndex": 3,
  "chunkCount": 11,
  "pageStart": 4,
  "pageEnd": 5,
  "charCount": 3998,
  "wordCount": 654,
  "markdown": "two are similar in theoretical complexity, dot-product attention is much faster and more space-efficient in practice, since it can be implemented using highly optimized matrix multiplication code.\n\nWhile for small values of dk the two mechanisms perform similarly, additive attention outperforms dot ...",
  "isScanned": false
}
```

A page item (`splitBy: page`) has `pageNumber` and a per-page `isScanned`.

Export to JSON, CSV, Excel, or use the Apify API, LangChain / LlamaIndex Apify loaders, Make, Zapier or n8n.

### Pricing

You pay per **dataset item saved**, so the cost depends on `splitBy`:

- `document`: **1 item per PDF**, the cheapest option
- `page`: **1 item per page**, so a 20-page PDF = 20 items
- `chunk`: **1 item per chunk**, so a 60,000-character PDF with 4,000-character chunks ≈ 16 items

Use `maxPages` to cap what you read and set a **maximum cost per run** in the run options; the Actor stops when it is reached. Failed URLs (not a PDF, password-protected, too large, 403/404, no extractable text) are **not charged**. They are listed in the key-value store record `FAILED` with the reason.

### Limits (honest)

- **No OCR.** Scanned or image-only PDFs have little or no text layer. Those pages get `isScanned: true`; a PDF with no text at all goes to `FAILED` (free). Run OCR elsewhere for those.
- **Markdown is heuristic.** Headings come from font size and numbered titles; bold-only headings at body size are not detected. Tables become plain lines of text, and multi-column layouts follow the PDF's internal text order (usually correct for papers, sometimes not for magazines or flyers).
- Hyphen fixing can merge real compounds split at a line end (e.g. "sequence-aligned" → "sequencealigned").
- Math formulas come out as plain characters, not LaTeX.
- The link must return the PDF itself. Pages that only show a PDF viewer or need a login won't work.
- Password-protected PDFs are skipped.
- `language` is a simple stopword guess for English, German, French, Spanish, Italian, Portuguese, Dutch and Malay; `null` when unsure.

### FAQ

**Do I need an account or API key?** Only an Apify account. No other keys, logins or proxies.

**Can I extract a PDF from my own storage?** Yes, as long as there is a direct download URL (for example a public S3 / Google Cloud Storage link, or a signed URL).

**Is it legal?** The Actor only downloads files from the URLs you provide. You are responsible for having the right to process those documents and for complying with copyright, the source's terms and data-protection laws such as GDPR if a document contains personal data.

# Actor input Schema

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

Direct links to PDF files (e.g. https://arxiv.org/pdf/1706.03762). Each link must return the PDF itself, not an HTML page that embeds it.

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

Plain text, Markdown (headings detected by font size, paragraphs joined, hyphenated line breaks fixed), or both.

## `splitBy` (type: `string`):

Document = one dataset item per PDF. Page = one item per page. Chunk = overlapping chunks of about "Chunk size" characters, ready for RAG / embeddings. You pay per dataset item, so Page and Chunk cost more per PDF.

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

Target size of each chunk when splitting by chunk. Chunks are cut at paragraph, sentence or word boundaries. 4000 characters is roughly 1000 tokens.

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

How many characters each chunk repeats from the end of the previous chunk, so context is not lost at chunk borders. Capped at half the chunk size.

## `maxPages` (type: `integer`):

Only read the first N pages of each PDF. 0 = all pages.

## `includeMetadata` (type: `boolean`):

Add title, author, subject, keywords, creator, producer, creation and modification date from the PDF's document info.

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

Skip PDFs larger than this (listed in FAILED, not charged).

## Actor input object example

```json
{
  "pdfUrls": [
    "https://arxiv.org/pdf/1706.03762"
  ],
  "outputFormat": "both",
  "splitBy": "document",
  "chunkSize": 4000,
  "chunkOverlap": 200,
  "maxPages": 0,
  "includeMetadata": true,
  "maxFileSizeMb": 50
}
```

# Actor output Schema

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

No description

## `failed` (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://arxiv.org/pdf/1706.03762"
    ]
};

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

# Run the Actor and wait for it to finish
run = client.actor("rasareka/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://arxiv.org/pdf/1706.03762"
  ]
}' |
apify call rasareka/pdf-text-extractor --silent --output-dataset

```

## MCP server setup

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