# PDF to Markdown — text layer and OCR, per page (`hermeskd/pdf-to-markdown`) Actor

PDF URLs in, clean Markdown out, page by page, with page count and basic metadata. Text-layer pages convert directly; scanned pages are OCR'd. Pay per page.

- **URL**: https://apify.com/hermeskd/pdf-to-markdown.md
- **Developed by:** [Logan Parker](https://apify.com/hermeskd) (community)
- **Categories:** Agents, AI, Developer tools
- **Stats:** 3 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.40 / 1,000 pdf page converteds

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

Give it one or more PDF URLs; it returns each document as clean Markdown, page by page, with the page count and basic document metadata. Pages that carry a text layer are converted directly; scanned pages are run through OCR when `ocr` is `auto` or `always`. Use it whenever you hold a link to a PDF (a paper, a filing, a manual, an invoice you were given) and need its text in your context. Pricing is per page, so a short document costs a fraction of a cent, and every page is numbered so an agent can cite it.

### Call it from an agent

Through Apify's MCP server (`https://mcp.apify.com`), tool `call-actor`:

```json
{"actor": "hermeskd/pdf-to-markdown", "input": {"urls": ["https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"]}, "callOptions": {"maxTotalChargeUsd": 0.05, "timeout": 3600}, "waitSecs": 30}
```

The call returns the run's status and its `defaultDatasetId`. Read the records with `get-dataset-items`:

```json
{"datasetId": "<defaultDatasetId from the call>", "limit": 50}
```

As a dedicated tool, add `https://mcp.apify.com?tools=hermeskd/pdf-to-markdown` to your MCP client. Single short documents finish well inside the 30-second wait, so one `call-actor` plus one `get-dataset-items` is the whole exchange. `maxTotalChargeUsd` caps what the run can charge; when it is reached the remaining URLs come back as `charge_limit_reached` records and are not charged.

### Input

| Field | Type | Required | Default | Meaning |
|---|---|---|---|---|
| `urls` | array of strings | yes | — | PDF URLs, http or https, 1–50 per run. |
| `ocr` | enum `auto` · `always` · `never` | no | `auto` | `auto` OCRs only pages with no usable text layer. |
| `ocrLanguages` | array of strings | no | `["eng"]` | OCR language codes (ISO 639-2, e.g. `eng`, `deu`, `fra`); at most 3. Supported: eng, deu, fra, spa, ita, por, nld, pol, ces, swe, dan, nor, fin, tur, rus, ukr. |
| `pages` | string | no | all | Page ranges, e.g. `1-5,8,10-12`, applied to every document. |
| `maxPagesPerDocument` | integer | no | 300 | Pages beyond this are not converted (1–2,000). |
| `includePages` | boolean | no | `true` | Include the per-page array; `false` returns the joined Markdown only. |

Every limit above is enforced by the input schema and again in code.

### Output

One record per input URL.

| Field | Meaning |
|---|---|
| `url` | The input URL. |
| `ok` | `true` when the document converted; `false` with `error`. |
| `pageCount` | Pages in the document. |
| `pagesConverted` | Pages converted from the text layer (charged as `pdf-page-converted`). |
| `pagesOcr` | Pages converted by OCR (charged as `pdf-page-ocr`). |
| `title` | Document title from metadata, when present. Author and other person fields are never returned. |
| `createdAt` | Creation date from metadata, ISO 8601, when present. |
| `markdown` | The whole document, pages separated by a blank line, `---` and a blank line. |
| `pages` | Array of `{number, markdown, ocr}` when `includePages`. |
| `warnings` | `page_limit` when pages over `maxPagesPerDocument` were skipped; `charge_limit` when the run's maximum charge stopped the document early. The record stays `ok: true` and only converted pages are charged. |
| `error` | `{code, message}` when `ok` is `false`. |

Example record for the call above, as this Actor returned it in its deploy check on 2026-10-16:

```json
{
  "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
  "ok": true,
  "pageCount": 1,
  "pagesConverted": 1,
  "pagesOcr": 0,
  "title": null,
  "createdAt": "2007-02-23T17:56:37+02:00",
  "markdown": "Dummy PDF file",
  "pages": [
    {"number": 1, "markdown": "Dummy PDF file", "ocr": false}
  ],
  "warnings": []
}
```

### Events and prices

Pay per event; platform usage is included in the price, never passed through.

| Event | Title | Charged when | FREE / BRONZE | SILVER | GOLD / PLATINUM / DIAMOND |
|---|---|---|---|---|---|
| `pdf-page-converted` | PDF page converted | One page converted from its text layer to Markdown. | $0.0005 | $0.00045 | $0.0004 |
| `pdf-page-ocr` | PDF page converted with OCR | One scanned page converted by OCR; charged instead of, not in addition to, pdf-page-converted. | $0.003 | $0.0027 | $0.0024 |

Apify also charges its standard `apify-actor-start` event: $0.00005 per GB of run memory (2 events, $0.0001, at the default 2,048 MB). The minimum maximum-charge a caller can set is $0.01.

Worked example on the FREE tier: a 10-page PDF with a text layer costs 10 × $0.0005 = $0.005, plus $0.0001 for the start, $0.0051 in all. A 10-page scan costs 10 × $0.003 = $0.03 plus the start. Nothing is charged for a failed document.

### Limits and run time

- 1–50 URLs per run; files up to 100 MB; up to 2,000 pages per document (300 by default).
- Each request — its redirects and its whole body included — must finish within 30 seconds (the per-request timeout; a slower file is `download_failed`); at most 2 requests a second go to one host.
- Default run memory 2,048 MB (from 1,024 to 8,192 MB), which Apify runs on half a CPU core; documents are converted one at a time, and on the largest inputs tested (300 pages, a 95 MB scan, fifty URLs) a run peaked under 400 MiB.
- Typical run time at the default memory: a one-page text PDF in a few seconds; text pages at about 5 a second (300 pages in about a minute); OCR at about 4 seconds a page with one language and about 7 with three. The default run timeout is 3,600 seconds.
- OCR runs on one core at a time, so its time halves at 4,096 MB (a whole core) and does not fall further above it; the price per page stays the same. A 300-page scan takes about 20 minutes with one language and about 35 with three at the default; to finish sooner, start the run with `memory` 4,096. A document that runs out of time returns `timeout` and nothing is charged for it.

### Errors

Errors are records with `ok: false` and `error.code`; none is charged.

| `error.code` | Meaning |
|---|---|
| `download_failed` | The URL did not return the file (status or network error). |
| `not_pdf` | The response is not a PDF, or the file is damaged and cannot be read as one. |
| `too_large` | Larger than 100 MB. |
| `encrypted` | Password-protected. |
| `robots_disallowed` | robots.txt forbids fetching the URL. |
| `blocked_host` | The host is on the deny-list, or resolves to a private or local address. |
| `timeout` | The document did not finish within the run's time budget. |
| `internal_error` | Unexpected failure; message carries the class. |
| `charge_limit_reached` | The run reached its maximum total charge before this URL; it was not processed. |
| `invalid_input` | The run input passed the input schema but cannot be used (for example a descending page range such as `5-3`, or no URL at all); the message names the field. One record per input given, or one with `url: null` when none was given; nothing is processed. |

The run fails only when every input failed with an Actor-side code (`internal_error`, `timeout`), so a broken Actor is visible. Every other run succeeds — including one where nothing converted because of the caller's own inputs (bad URL, robots, deny-list, not found, invalid input, the charge limit), or where those and Actor-side failures are mixed.

### Sources and terms

The source is the caller's PDF. Process only documents you have the right to process. Fetching follows the Hermes fetch policy: robots.txt is obeyed for the user-agent `HermesBot` (and `*`), and a disallowed URL is refused without a request; platforms whose terms forbid automated access, and people-search sites, are on a deny-list and refused without a request; private and local addresses are refused, after DNS and on every redirect; the user-agent is `HermesBot/1.0 (+https://apify.com/hermeskd)`; no login, cookies, credentials, CAPTCHA solving, evasion or proxies are used. Document metadata is limited to the title and creation date; author fields are dropped.

### Not affiliated

This Actor is not affiliated with Adobe or with any publisher of the documents it converts. Tesseract, pdfminer.six, pypdfium2 and pypdf are used under their open-source licences.

### Related Hermes Actors

- `document-to-markdown` — Word, PowerPoint, Excel and other office files to Markdown.
- `image-to-text` — OCR for images.
- `audio-to-transcript` — speech to text.
- `video-frames` — frames and metadata from a video.
- `image-upscale` — image upscaling.
- `url-to-markdown` — a web page to Markdown.
- `audio-video-convert` — audio and video format conversion.

### Changelog

- 1.0 (2026-10-16) — input the Actor cannot use is answered with `invalid_input` records and the run succeeds; a run fails only when every input failed on the Actor's side.
- 1.0 (2026-10-14) — first release: text layer and OCR per page, page ranges, page cap, per-page output.

# Actor input Schema

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

PDF URLs, http or https, 1–50 per run. Each URL becomes one record.

## `ocr` (type: `string`):

auto OCRs only pages with no usable text layer; always OCRs every page; never uses the text layer only.

## `ocrLanguages` (type: `array`):

OCR language codes (ISO 639-2, e.g. eng, deu, fra); at most 3.

## `pages` (type: `string`):

Page ranges, e.g. 1-5,8,10-12, applied to every document. Empty means all pages.

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

Pages beyond this are not converted (1–2,000); the record carries the warning page_limit and only converted pages are charged.

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

Include the per-page array; false returns the joined Markdown only.

## Actor input object example

```json
{
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "ocr": "auto",
  "ocrLanguages": [
    "eng"
  ],
  "maxPagesPerDocument": 300,
  "includePages": true
}
```

# Actor output Schema

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

One record per input URL with ok, markdown, pages and error.

# 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.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("hermeskd/pdf-to-markdown").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.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"] }

# Run the Actor and wait for it to finish
run = client.actor("hermeskd/pdf-to-markdown").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.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ]
}' |
apify call hermeskd/pdf-to-markdown --silent --output-dataset

```

## MCP server setup

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

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/yIbsWwtSgGZ7u0FGZ/builds/HZbjbWxs2R1HzzO6v/openapi.json
