# PDF Text Extractor (`landlordtools/pdf-text-extractor`) Actor

Extracts the text layer from PDFs at http(s) URLs, page by page, with page counts and a needsOcr flag for scanned pages. No OCR, no browser.

- **URL**: https://apify.com/landlordtools/pdf-text-extractor.md
- **Developed by:** [LandlordTools](https://apify.com/landlordtools) (community)
- **Categories:** AI, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 pdfs

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 Text Extractor

Turn PDF links into plain text for search, RAG or AI agents. Each PDF is read page by page with Mozilla's PDF.js [1]: text with pages separated, page and word counts, and a `needsOcr` flag for scanned pages. No OCR, no browser.

### What it does

- **Text layer only**, page by page; each page is released before the next, so long documents don't grow memory.
- **Scans flagged, not guessed**: a page with no text layer is marked `needsOcr` and listed in `pagesNeedingOcr`. Usually a scan or outlined text; blank pages are flagged too. No OCR is run or charged.
- **Pages** are separated by a form feed (`\f`) in `text`, as `pdftotext` does. `pages` gives characters, words and `needsOcr` for each page.
- **Checks**:
  - the file must start with the `%PDF-` header [2];
  - password-protected or damaged files give a clear error;
  - redirects are followed (up to 5).
- **Limits you set**: file size, pages, characters and time per PDF. Pages read before a limit are kept; `stoppedEarly` says why.
- **Safety**: only http and https. Private, loopback, link-local and cloud metadata addresses are refused [3][4], including after DNS and on every redirect.

### Quick start

The prefilled input reads one GOV.UK PDF:

```json
{
  "urls": [
    "https://assets.publishing.service.gov.uk/media/5a7e3de4ed915d74e622507f/legal-aid-checklist.pdf"
  ]
}
```

The row from the run on 4 October 2026, without `text` and `pages`:

```json
{
  "index": 0,
  "url": "https://assets.publishing.service.gov.uk/media/5a7e3de4ed915d74e622507f/legal-aid-checklist.pdf",
  "finalUrl": "https://assets.publishing.service.gov.uk/media/5a7e3de4ed915d74e622507f/legal-aid-checklist.pdf",
  "status": 200,
  "title": "Civil representation - Checklist for new applications - August 2013",
  "pageCount": 4,
  "pagesRead": 4,
  "chars": 2531,
  "words": 492,
  "needsOcr": false,
  "pagesNeedingOcr": [],
  "textTruncated": false,
  "stoppedEarly": null,
  "bytes": 157341,
  "error": null
}
```

`text` starts "Civil Representation\nChecklist for new applications\nAugust 2013 v2".

### Input

| Field | Default | Meaning |
|---|---|---|
| `urls` | (required) | PDF links, up to 1,000 |
| `maxPages` | 500 | Pages read per PDF |
| `maxFileMB` | 30 | Largest file downloaded |
| `maxCharsPerPdf` | 1,000,000 | Text kept per PDF |
| `timeoutSecs` | 60 | Download and reading, per PDF |
| `maxConcurrency` | 2 | Most PDFs at once (1–4), within memory |

### Output

One row per PDF, with `index` giving its position in `urls`. Rows arrive as each PDF finishes.

| Field | Meaning |
|---|---|
| `text` | Page texts joined by `\f` |
| `pages` | `[{page, chars, words, needsOcr}]` |
| `needsOcr`, `pagesNeedingOcr` | Scanned pages, if any |
| `title`, `pageCount`, `pagesRead`, `chars`, `words` | From the document |
| `status`, `finalUrl`, `bytes` | The download |
| `textTruncated`, `stoppedEarly`, `error` | What stopped it |

### Use from code

```bash
curl -X POST "https://api.apify.com/v2/acts/landlordtools~pdf-text-extractor/run-sync-get-dataset-items?token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"urls": ["https://assets.publishing.service.gov.uk/media/5a7e3de4ed915d74e622507f/legal-aid-checklist.pdf"]}'
```

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

const client = new ApifyClient({ token: 'YOUR_API_TOKEN' });
const run = await client.actor('landlordtools/pdf-text-extractor').call({ urls: ['https://example.org/report.pdf'] });
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items[0].text.split('\f')[0]);
```

### Use with AI agents

Agents can call it through Apify's MCP server (https://mcp.apify.com) to read a PDF instead of guessing what it says.

### Accuracy

Tested on 4 and 10 October 2026 against poppler's `pdftotext` on 200 GOV.UK PDFs (7,785 pages), using word-level F1:

- median 0.998 per PDF;
- 0.988 over all words pooled;
- 191 of the 200 PDFs at 0.95 or above.

The lowest scores are forms and multi-column layouts. No errors on either side. Details: `tests/benchmark/`.

### Limits

- No OCR: scanned pages come back empty and flagged `needsOcr`. A scan with a few typed characters on it (such as a page number) isn't flagged.
- Memory: 256 MB reads one PDF at a time; 512 MB reads two.
- Reading order follows the PDF's text positions. Multi-column layouts and tables may interleave.
- Forms: field values typed into a form aren't part of the text layer.

### Integrations

Power Platform, OpenAPI, Excel and Google Sheets files are in [`integrations/`](integrations/README.md). Apify's Zapier, Make and n8n apps work too.

### Pricing

Pay per event: $2 per 1,000 results ($0.002 each), plus Apify's minimal start fee. A result is one PDF read, whatever its length. PDFs that can't be fetched or read are free, and the run stops at your spending limit [5].

### Related Actors

- [Link and Citation Checker](https://apify.com/landlordtools/link-citation-checker): check that links and quotes are right.
- [Sitemap URL Extractor](https://apify.com/landlordtools/sitemap-extractor): find every page on a site.

### Sources

1. [pdfjs-dist (Mozilla PDF.js), Apache-2.0](https://www.npmjs.com/package/pdfjs-dist). Accessed 4 October 2026.
2. [Library of Congress: PDF 1.7 (ISO 32000-1:2008) format description, file header %PDF-](https://www.loc.gov/preservation/digital/formats/fdd/fdd000277.shtml). Accessed 4 October 2026.
3. [IANA IPv4 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv4-special-registry/). Accessed 4 October 2026.
4. [IANA IPv6 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv6-special-registry/). Accessed 4 October 2026.
5. [Apify: pay-per-event pricing](https://docs.apify.com/platform/actors/publishing/monetize/pay-per-event). Accessed 4 October 2026.

[1]: https://www.npmjs.com/package/pdfjs-dist

[2]: https://www.loc.gov/preservation/digital/formats/fdd/fdd000277.shtml

[3]: https://www.iana.org/assignments/iana-ipv4-special-registry/

[4]: https://www.iana.org/assignments/iana-ipv6-special-registry/

[5]: https://docs.apify.com/platform/actors/publishing/monetize/pay-per-event

# Actor input Schema

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

Links to PDF files, up to 1,000. Each is downloaded once; private-network addresses are refused.

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

Default 500.

## `maxFileMB` (type: `integer`):

Bigger files aren't downloaded. Default 30.

## `maxCharsPerPdf` (type: `integer`):

Text beyond this is cut (textTruncated). Default 1,000,000.

## `timeoutSecs` (type: `integer`):

Download and reading together. Pages read in time are kept. Default 60.

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

Default 2. The run also limits this to what its memory allows: 1 PDF at a time at 256 MB, 2 at 512 MB.

## Actor input object example

```json
{
  "urls": [
    "https://assets.publishing.service.gov.uk/media/5a7e3de4ed915d74e622507f/legal-aid-checklist.pdf"
  ]
}
```

# Actor output Schema

## `result` (type: `string`):

No description

## `output` (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://assets.publishing.service.gov.uk/media/5a7e3de4ed915d74e622507f/legal-aid-checklist.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("landlordtools/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 = { "urls": ["https://assets.publishing.service.gov.uk/media/5a7e3de4ed915d74e622507f/legal-aid-checklist.pdf"] }

# Run the Actor and wait for it to finish
run = client.actor("landlordtools/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 '{
  "urls": [
    "https://assets.publishing.service.gov.uk/media/5a7e3de4ed915d74e622507f/legal-aid-checklist.pdf"
  ]
}' |
apify call landlordtools/pdf-text-extractor --silent --output-dataset

```

## MCP server setup

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