# PDF and Image to Markdown and Text - Tables and OCR (`kinglabbok/pdf-to-markdown`) Actor

Convert PDF files and images to clean Markdown or plain text. Keeps headings, lists and tables, reads two-column pages in the right order and runs OCR on scanned pages, screenshots and photos (PNG, JPEG, TIFF, WebP). No external AI services. Built for RAG pipelines and AI agents.

- **URL**: https://apify.com/kinglabbok/pdf-to-markdown.md
- **Developed by:** [Fayoz](https://apify.com/kinglabbok) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 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.

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 and Image to Markdown and Text - Tables and OCR

Convert PDF files and images into clean Markdown or plain text that language models and search indexes can use directly. The Actor keeps headings, lists and tables, reads two-column pages in the right order and runs OCR on scanned pages that have no text layer. Images (PNG, JPEG, TIFF, WebP, GIF, BMP) are read with OCR too, so the same Actor turns screenshots, photos of documents and scanned images into text.

It runs entirely inside the Actor: no external AI service is called, so your documents are not sent to a third party and the price per page stays low and predictable.

### What it does

- **Headings** - detected from font size and weight and returned as `#`, `##`, `###`.
- **Lists** - bullets and numbered items are kept as list items.
- **Tables** - tables drawn with lines are returned as Markdown tables at their place in the text.
- **Two-column pages** - the left column is read before the right one, so paragraphs are not mixed line by line. Label-value layouts such as invoices are kept row by row.
- **Scanned pages** - pages without a text layer are recognised with Tesseract OCR. Nine languages are installed: `eng`, `deu`, `fra`, `spa`, `ita`, `por`, `nld`, `pol`, `rus`.
- **Images** - PNG, JPEG, TIFF, WebP, GIF and BMP files are read with OCR. Every frame of a multi-page TIFF is one page. Photo rotation from the camera (EXIF) is applied, very large photos are scaled down and small screenshots are scaled up before OCR.
- **Per-document or per-page results** - get the whole document in one field, or one result per page for chunking and citations with page numbers.
- **Clear failures** - a broken link or a file that is neither a PDF nor an image is reported in the results with `status: "failed"` and a reason. The run itself still finishes successfully.

### Typical uses

- Prepare contracts, reports, manuals and research papers for retrieval-augmented generation (RAG).
- Give an AI agent the content of a PDF found on the web.
- Turn scanned invoices, letters and photos of documents into searchable text.
- Read the text of screenshots and images in bulk (image to text).
- Extract tables from reports into Markdown that a model can read.

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `pdfUrls` | array of strings | required | Direct, publicly reachable links to PDF files or images (PNG, JPEG, TIFF, WebP, GIF, BMP). The file type is read from the file itself. |
| `outputFormat` | `markdown` or `text` | `markdown` | Markdown keeps structure. Text removes the Markdown markers. |
| `outputMode` | `document` or `page` | `document` | One result per document, or one result per page. |
| `extractTables` | boolean | `true` | Return ruled tables as Markdown tables. |
| `ocr` | `auto`, `off`, `force` | `auto` | Auto runs OCR only on pages with no text layer. Images are always read with OCR (they fail with `off`). |
| `ocrLanguages` | string | `eng` | Tesseract codes joined with `+`, for example `eng+deu`. |
| `pageRange` | string | all pages | For example `1-3,5,8-`. Pages start at 1. For multi-page TIFF files the frames are the pages. |
| `maxPagesPerDocument` | integer | `0` | Stop after this many pages per document. `0` means no limit. |
| `maxFileSizeMb` | integer | `50` | Larger files are skipped and reported as failed. Maximum 200. |
| `includePageMarkers` | boolean | `false` | Insert `<!-- page N -->` before each page (document layout, Markdown only). |

Example:

```json
{
    "pdfUrls": ["https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"],
    "outputFormat": "markdown",
    "outputMode": "document",
    "ocr": "auto"
}
```

Example with images:

```json
{
    "pdfUrls": ["https://example.com/scan-001.png", "https://example.com/receipt.jpg"],
    "outputFormat": "text",
    "ocrLanguages": "eng+deu"
}
```

To convert a file from your computer, upload it to any location that gives a direct link, for example an Apify key-value store record, and pass that link.

### Output

One result per document (default layout):

```json
{
    "url": "https://example.com/report.pdf",
    "fileName": "report.pdf",
    "fileType": "pdf",
    "status": "succeeded",
    "errorMessage": null,
    "title": "Quarterly Report",
    "author": null,
    "creationDate": "2026-01-15T09:30:00+02:00",
    "pageCount": 12,
    "pagesProcessed": 12,
    "ocrPages": 2,
    "tableCount": 3,
    "charCount": 18450,
    "wordCount": 2980,
    "markdown": "# Quarterly Report\n\n## Summary\n\nRevenue grew by 12 percent...\n\n| Region | Q1 | Q2 |\n| --- | --- | --- |\n| Europe | 120 | 135 |",
    "truncated": false,
    "fullOutputUrl": null,
    "pageErrors": [],
    "fileSizeBytes": 482113,
    "sha256": "3f1c...",
    "processedAt": "2026-11-15T10:00:00+00:00",
    "durationMs": 840
}
```

`fileType` is `pdf`, `png`, `jpeg`, `tiff`, `webp`, `gif` or `bmp`. For images `title`, `author` and `creationDate` are null and `ocrPages` equals `pagesProcessed`.

In per-page layout each result has `page`, `markdown` or `text`, `tableCount`, `ocr` and `charCount`, plus the document fields `url`, `fileName`, `fileType`, `title`, `author` and `pageCount`.

Very long documents: when the content is longer than 2,000,000 characters the result holds the first part, `truncated` is `true` and `fullOutputUrl` links to the complete file.

### Pricing

Pay per event. You pay only for pages that were converted.

| Event | Price |
|---|---|
| Actor start | $0.00005 |
| Page with a text layer | $0.001 |
| Page converted with OCR | $0.004 |

Every image (or every frame of a multi-page TIFF) is one page converted with OCR.

Examples: a 40-page report with a text layer costs about $0.04. A 10-page scanned contract costs about $0.04. 1,000 screenshots cost $4. Failed downloads are not charged.

Set a maximum cost per run in the run options and the Actor stops before it is exceeded.

**Free plan:** up to 30 pages per run. The Actor stops with a clear message when the limit is reached. Paid Apify plans have no page limit.

### Limits and honest notes

- Tables without ruling lines are returned as text rows, not as Markdown tables.
- Heading detection relies on font sizes. Documents that use one size everywhere come out as plain paragraphs.
- OCR quality depends on the scan. Skewed or low-resolution pages and photos give weaker text. Handwriting is not supported.
- Formulas, charts and images are not converted. Text inside images is read only when the page goes through OCR.
- Password-protected PDFs are reported as failed.
- The Actor downloads only the links you provide. It does not crawl websites.

### FAQ

**Can an AI agent call this Actor?** Yes. The input is small and typed, and the output is one JSON record per document or per page.

**Does it send my documents anywhere?** No. Conversion and OCR run inside the Actor container. Results are stored in your own Apify dataset.

**Which languages does OCR support?** English, German, French, Spanish, Italian, Portuguese, Dutch, Polish and Russian. Combine them with `+`.

**Can it read images?** Yes: PNG, JPEG, TIFF, WebP, GIF and BMP. Pass the image links in `pdfUrls`, the same way as PDF links.

**What happens with a link that is neither a PDF nor an image?** The result for that link has `status: "failed"` and `errorMessage` explains why. Other links in the same run are still processed.

### Changelog

See `CHANGELOG.md`.

# Changelog

This Actor's version history is a separate document: https://apify.com/kinglabbok/pdf-to-markdown/changelog.md

# Actor input Schema

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

Direct links to the PDF files or images (PNG, JPEG, TIFF, WebP, GIF, BMP) you want to convert. Each link must be publicly reachable over http or https. One result is returned per file.

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

Markdown keeps headings, lists and tables. Text returns the same content without Markdown markers.

## `outputMode` (type: `string`):

One result per document with the full content, or one result per page (useful for chunking and citations with page numbers).

## `extractTables` (type: `boolean`):

Detect tables drawn with lines and return them as Markdown tables in their place in the text.

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

Auto runs OCR only on pages that have no text layer. Off never runs OCR. Force runs OCR on every page (slower, charged at the OCR rate). Images are always read with OCR.

## `ocrLanguages` (type: `string`):

Tesseract language codes joined with a plus sign, for example eng or eng+deu. Available: eng, deu, fra, spa, ita, por, nld, pol, rus.

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

Pages to convert, for example 1-3,5,8- (pages start at 1). Leave empty to convert all pages.

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

Stop after this many pages in each document. Use 0 for no limit.

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

Files larger than this are skipped and reported as failed.

## `includePageMarkers` (type: `boolean`):

In document layout with Markdown output, insert an HTML comment such as  before each page.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "outputFormat": "markdown",
  "outputMode": "document",
  "extractTables": true,
  "ocr": "auto",
  "ocrLanguages": "eng",
  "maxPagesPerDocument": 0,
  "maxFileSizeMb": 50,
  "includePageMarkers": false
}
```

# Actor output Schema

## `results` (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.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("kinglabbok/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 = { "pdfUrls": ["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("kinglabbok/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 '{
  "pdfUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ]
}' |
apify call kinglabbok/pdf-to-markdown --silent --output-dataset

```

## MCP server setup

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