# PDF to Text Extractor (`touchrock/pdf-to-text`) Actor

Extract the text of PDFs from URLs or uploaded files, page by page or as one document. $3 per 1,000 pages with text; scanned pages without text, failed downloads and broken PDFs are free. No OCR.

- **URL**: https://apify.com/touchrock/pdf-to-text.md
- **Developed by:** [Touchrock](https://apify.com/touchrock) (community)
- **Categories:** 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 page with texts

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 Extractor

Extract the text of PDF files, page by page or as one document. Give it direct links to PDFs (or upload one file) and
get clean text in a dataset you can download as JSON, CSV or Excel, or read through the Apify API.

### What it does

- Downloads only the PDFs you list (up to 500 per run, up to 100 MB each). It does not crawl websites.
- Reads the **text layer** of each page with [pdf.js](https://mozilla.github.io/pdf.js/) (through
  [unpdf](https://github.com/unjs/unpdf)).
- Returns one row per page, or one row per PDF with the pages joined and marked `--- Page N ---`.
- Tells you which pages had no text, and which files failed and why.

### What it does not do

- **No OCR.** A scanned page is an image: it has no text layer, so it comes back empty with `hasText: false`.
  **Pages without text are never charged.** If you need OCR, use an OCR Actor for those pages.
- No password-protected PDFs (reported as an error, not charged).
- Layout is simplified: text comes in reading order, line by line; tables become plain lines of text.

### Pricing (pay per event)

| Event | Price | When |
|---|---|---|
| Page with text | **$0.003** ($3 per 1,000 pages) | One page whose text was extracted |

Free: pages without text (scans, blank pages), files that fail to download, files that are not PDFs, broken or
password-protected PDFs, and pages beyond your "Max pages per PDF". Your maximum cost per run is respected: when it is
reached the run stops and the pages left out are not charged.

Example: a 6-page text PDF plus a 1-page scan costs 6 × $0.003 = **$0.018**.

### Input

```json
{
    "pdfUrls": [
        "https://www.irs.gov/pub/irs-pdf/fw9.pdf"
    ],
    "outputFormat": "perPage",
    "maxPagesPerPdf": 1000
}
```

- `pdfUrls`: direct links to PDF files.
- `pdfFile` (optional): upload one PDF from your computer in the Apify Console.
- `outputFormat`: `perPage` (one row per page, default) or `perDocument` (one row per PDF).
- `maxPagesPerPdf`: read only the first N pages of each PDF.

### Output

One row per page (`perPage`):

```json
{
    "url": "https://www.irs.gov/pub/irs-pdf/fw9.pdf",
    "fileName": "fw9.pdf",
    "pageNumber": 1,
    "totalPages": 6,
    "hasText": true,
    "charCount": 5658,
    "text": "Form W-9(Rev. March 2024)\nRequest for Taxpayer\nIdentification Number and Certification\n..."
}
```

A file that fails gives one free row with `error` set, for example `"download failed: HTTP 404"` or
`"the file is not a PDF"`.

The `OUTPUT` record of the run's key-value store has a summary: PDFs read, pages with and without text, pages charged
and the errors.

### Use cases

- Feed PDF reports, papers, manuals or forms into a search index, a spreadsheet or an LLM pipeline.
- Check which PDFs in a list are scans (no text layer) before sending only those to OCR.

### Notes

- Only process files you have the right to use. The Actor reads the files you give it and nothing else.
- Questions or a PDF that comes out wrong? Open an issue on this Actor's page.

# Actor input Schema

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

Direct links to PDF files (up to 500 per run). Only the files you list are downloaded; no crawling.

## `pdfFile` (type: `string`):

Upload one PDF from your computer. It is read together with the URLs above.

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

One dataset row per page, or one row per PDF with all pages joined and marked "--- Page N ---". The price is the same.

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

Only the first N pages of each PDF are read (and charged).

## Actor input object example

```json
{
  "pdfUrls": [
    "https://www.irs.gov/pub/irs-pdf/fw9.pdf"
  ],
  "outputFormat": "perPage",
  "maxPagesPerPdf": 1000
}
```

# Actor output Schema

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

No description

## `summary` (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://www.irs.gov/pub/irs-pdf/fw9.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("touchrock/pdf-to-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 = { "pdfUrls": ["https://www.irs.gov/pub/irs-pdf/fw9.pdf"] }

# Run the Actor and wait for it to finish
run = client.actor("touchrock/pdf-to-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 '{
  "pdfUrls": [
    "https://www.irs.gov/pub/irs-pdf/fw9.pdf"
  ]
}' |
apify call touchrock/pdf-to-text --silent --output-dataset

```

## MCP server setup

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