# PDF Text Extractor: Markdown, RAG Chunks, OCR & Search (`pikoulas/pdf-text`) Actor

Extract text from PDFs as Markdown or plain text for AI and RAG: chunks with their page and heading, keyword mentions by page, a file per PDF and one for the run. Page ranges, OCR for scans in 18 languages. By URL, no API key. $2 per 1,000 PDFs; no text, no charge.

- **URL**: https://apify.com/pikoulas/pdf-text.md
- **Developed by:** [Spyridon Pikoulas](https://apify.com/pikoulas) (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 reads

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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 Text Extractor: Markdown, RAG Chunks, OCR & Search

Give it the addresses of PDF files and get their content back ready for an AI model:

- **Markdown that keeps the structure:** headings from the font sizes, bold, bullet lists and code
  blocks, paragraphs rejoined across line breaks and hyphenated words made whole. Or plain text.
- **Chunks for RAG:** each PDF split into passages of about the words you choose, whole paragraphs, a new one at a
  heading, each with its pages and the heading it falls under: ready to embed, and to cite by page.
- **Keyword search:** every place a word or phrase is said in each PDF, with its page and the text around it.
- **Files you can hand over:** each PDF as a Markdown file, never cut short, and the whole run's in one
  `documents.md` to drop into a chat or a knowledge base.
- **The pages you want:** a range such as `1-5, 8, 20-`, the whole document or page by page.
- **OCR for scanned pages**, only if you turn it on and only on pages with no text, in 18 languages
  from English, German and French to Arabic, Hindi, Chinese, Japanese and Korean.
- **Title, page count and dates** with each PDF, and files up to 100 MB.

It costs **$2 per 1,000 PDFs** on Apify's paid plans and $4 on the free plan, whatever their length.
OCR adds $3 per 1,000 scanned pages ($6 on the free plan). A PDF that can't be fetched or gives no
text costs nothing.

### What people use it for

- **AI and RAG pipelines:** reports, papers, manuals and filings as chunks to embed, each citing its page, or as
  Markdown to hand to an LLM whole.
- **Due diligence and compliance:** every mention of a company, a risk or a clause across a stack of reports,
  filings or contracts, by page.
- **Research:** the text of a list of public reports or papers without opening each one.
- **Monitoring:** a document published at a fixed URL, compared run by run.
- **Automation:** PDF text as one step of a Make, Zapier or n8n workflow, or a tool for an AI agent.

### How to extract text from a PDF

1. Click **Try for free**; Apify's free plan covers a first run.
2. Enter the **PDF URLs**.
3. Pick **Markdown** or **Plain text**, and the **Pages** if you want only some.
4. For RAG, set **Chunks for RAG**, 300 words for example; to search, add **Keyword mentions**.
5. Turn on **OCR scanned pages** if your files are scans, and pick their language.
6. Click **Start**, then download the results as JSON, CSV or Excel.

An input with every option:

```json
{
  "urls": ["https://www.rfc-editor.org/rfc/rfc9309.pdf"],
  "outputFormat": "markdown",
  "pageRange": "1-5, 8",
  "ocr": true,
  "ocrLanguage": "eng",
  "includePages": true,
  "chunkWords": 300,
  "keywords": ["crawler", "cache"],
  "saveFiles": true,
  "maxPagesPerPdf": 200
}
```

### Output

````json
{
  "url": "https://www.rfc-editor.org/rfc/rfc9309.pdf",
  "finalUrl": "https://www.rfc-editor.org/rfc/rfc9309.pdf",
  "fileName": "rfc9309.pdf",
  "title": "RFC 9309: Robots Exclusion Protocol",
  "pageCount": 12,
  "pagesRead": 12,
  "ocrPages": 0,
  "ocrSkippedPages": 0,
  "sizeBytes": 177688,
  "createdAt": "2022-09-09T17:39:45-07:00",
  "modifiedAt": "2022-09-09T17:39:47-07:00",
  "markdown": "# RFC 9309 Robots Exclusion Protocol\n\n## Abstract\n\nThis document specifies and extends the \"Robots Exclusion Protocol\" method originally defined by Martijn Koster in 1994…\n\n#### 2.2.1. The User-Agent Line\n\nCrawlers set their own name…\n\n```\n+==========================================+========================+\n| User-Agent HTTP header                   | robots.txt user-agent  |\n…",
  "truncated": false,
  "contentUrl": "https://api.apify.com/v2/key-value-stores/7qcdZpxnDJbJiqapF/records/00000-rfc9309.md?signature=1aOnge3Be0kEgE3QrCPe2",
  "keywordMentionCount": 16,
  "keywordMentions": [
    {"keyword": "crawler", "page": 3, "text": "A line with a key-value pair that defines how a crawler may access URIs. See Section 2.2.2. One or more user-agent lines that are followed by one or more r…"}
  ],
  "chunks": [
    {"index": 4, "pageStart": 4, "pageEnd": 5, "heading": "2.2.1. The User-Agent Line", "text": "#### 2.2.1. The User-Agent Line

Crawlers set their own name, which is called a product token, to find relevant groups. The product token contain only uppercase…", "words": 253}
  ],
  "error": null
}
````

That run, with `"chunkWords": 250` and two keywords, gave 17 chunks and 16 mentions; one of each is shown, and the
text shortened. The **Chunks** and **Keyword mentions** views list them one per row.

With **Plain text**, the content comes under `text` instead of `markdown`. `pages`, with **Text page
by page** on, holds each page's content, its number and whether OCR read it. A PDF that can't be read
comes with `url` and `error`, saying why. `ocrSkippedPages` counts scanned pages left without text:
OCR was off, or the spending limit came first. `contentUrl` opens the PDF's whole content as a file, as long as
the run's storage is kept; a dataset item holds up to about 8.5 MB, and past that `truncated` is true and the
file is the place to read it all.

### Use it as an API

Apify's API starts a run and returns its dataset as JSON; its Python and JavaScript clients, and
its Make, Zapier and n8n integrations, work the same way.

```bash
curl -X POST "https://api.apify.com/v2/acts/pikoulas~pdf-text/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"urls": ["https://www.rfc-editor.org/rfc/rfc9309.pdf"], "pageRange": "1-3"}'
```

AI agents can call it as a tool through Apify's MCP server: `https://mcp.apify.com?tools=pikoulas/pdf-text`.

### How much does it cost?

A PDF is $0.002 and a page read by OCR $0.003. A thousand text PDFs cost $2; a hundred scans of 20
pages each cost $6.20. Set a spending limit on a run and it stops there, with what it has read so far. Chunks, keyword mentions and the files cost nothing more.

### Good to know

- **How the Markdown is made.** It is read from the PDF's own layout: text larger than the body is a
  heading, a line in bold alone is a heading too, a fixed-pitch font is a code block. Tables come as
  their text in reading order, not as Markdown tables, and a page in columns as the PDF orders it.
- **Chunks follow the document:** paragraphs are never split, so a chunk can run past the words asked when a
  paragraph is long, and a heading starts a new chunk once the one under way is half full. A chunk's `heading` is
  the last heading before it starts. Keywords match whole words in any case, "cache" not "caches".
- **Text PDFs need no OCR:** leave it off and a 500-page PDF is read in seconds. With it on, only
  pages with almost no text and an image are read by OCR, so a PDF with text costs no more.
- **A site's refusal is respected.** It names itself in its User-Agent and reads each site's
  `robots.txt`, one request a second per site at most. A path `robots.txt` refuses isn't fetched,
  and a site that answers 401, 403 or 451, shows a verification page or answers 429 twice is left
  alone for the rest of the run; the rest of your list goes on. It uses no proxy and doesn't try
  to get past any of this, so a file behind a check comes back with an `error`.
- **Protected PDFs aren't read.** A PDF that needs a password, or whose permissions forbid copying its
  text, comes back with an `error`, and costs nothing.
- Only public addresses are fetched, not private networks.
- Very large text is cut to fit a dataset item, about 8 MB: `pages` goes first, then the end of the
  content, and `truncated` is `true`.
- OCR writes what it reads: tables and handwriting can come out wrong.
- **The author's name in a PDF's metadata is left out.** The text itself comes as it stands, names included.
- **Contact.** The Actor keeps nothing itself: each PDF stays on disk only while it's being read, and
  results sit in the dataset of whoever ran it. Questions or requests go to spyridwn.pd@gmail.com.
- Reads PDFs with PDFium and scanned pages with Tesseract OCR; based in part on the work of the
  FreeType Team.

### FAQ

#### Is it legal to extract text from PDFs?

It reads only the files you point it at, as anyone could download them, without logging in, and it
keeps to each site's `robots.txt`. You are responsible for having the right to use them: documents
are usually their authors' copyrighted work, a site's terms may limit how you use what it publishes,
including using it with AI models, and personal data in them is protected by laws such as the GDPR
and the CCPA. If you're unsure, ask a lawyer; Apify's
[Is web scraping legal?](https://blog.apify.com/is-web-scraping-legal/) is a good start.

#### Can it read scanned PDFs?

Yes, with **OCR scanned pages** on: a page with almost no text and an image is read with Tesseract
in the language you pick, and its text goes into the Markdown or text with the rest.

#### Does it read PDFs I upload?

It reads URLs. A file on your own computer needs an address first: upload it to a key-value store in
Apify Console (**Storage**) and give the record's signed URL, which the Actor reads through Apify's API.

#### Something missing or not working?

Open an issue on the **Issues** tab with the input you used, or ask there for a field you need.

If it does what you need, a review on the **Reviews** tab helps others find it.

# Actor input Schema

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

The addresses of the PDF files, such as https://www.rfc-editor.org/rfc/rfc9309.pdf, up to 100 MB each. A file in an Apify key-value store can be given by its signed URL.

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

Markdown keeps the document's structure for AI models and RAG: headings from the font sizes, bold, bullet lists and code blocks. Plain text is the text alone.

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

Which pages to read, such as 1-5, 8, 20- (page 20 to the end). Empty: every page, up to Max pages per PDF.

## `ocr` (type: `boolean`):

Reads pages that are images of text with Tesseract, charged per page. Pages that already have text are never charged for this.

## `ocrLanguage` (type: `string`):

The language of the scanned pages.

## `includePages` (type: `boolean`):

Adds each page's text apart, under pages, as well as the whole text.

## `chunkWords` (type: `integer`):

Also splits each PDF into chunks of about this many words, ready to embed: whole paragraphs, a new chunk at a heading once one is half full, each with its first and last page and the heading it starts under. 200 to 500 suits most embedding models. Empty: no chunks. Free.

## `keywords` (type: `array`):

Words or phrases to find in each PDF, whole words in any case: every place one is said, with its page and the text around it, under keywordMentions. Free.

## `saveFiles` (type: `boolean`):

Each PDF's whole content as a Markdown or text file in the run's key-value store, linked as contentUrl, and every PDF of the run in one documents.md (or .txt). Nothing is cut short in the files, even when a dataset item has to be.

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

Reads each PDF up to this page.

## Actor input object example

```json
{
  "urls": [
    "https://www.rfc-editor.org/rfc/rfc9309.pdf"
  ],
  "outputFormat": "markdown",
  "ocr": false,
  "ocrLanguage": "eng",
  "includePages": false,
  "saveFiles": true,
  "maxPagesPerPdf": 20
}
```

# Actor output Schema

## `overview` (type: `string`):

No description

## `chunks` (type: `string`):

No description

## `mentions` (type: `string`):

No description

## `documents` (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 = {
    "urls": [
        "https://www.rfc-editor.org/rfc/rfc9309.pdf"
    ],
    "maxPagesPerPdf": 20
};

// Run the Actor and wait for it to finish
const run = await client.actor("pikoulas/pdf-text").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.rfc-editor.org/rfc/rfc9309.pdf"],
    "maxPagesPerPdf": 20,
}

# Run the Actor and wait for it to finish
run = client.actor("pikoulas/pdf-text").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 '{
  "urls": [
    "https://www.rfc-editor.org/rfc/rfc9309.pdf"
  ],
  "maxPagesPerPdf": 20
}' |
apify call pikoulas/pdf-text --silent --output-dataset

```

## MCP server setup

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

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/HTYZXLjMioFaivCXg/builds/lISkumMWM5v2ON4Qi/openapi.json
