# PDF to Markdown & Text Converter for AI (`ohs999/pdf-to-markdown`) Actor

Convert PDFs to clean Markdown or plain text for LLMs, RAG and search: headings, lists and tables kept, headers and page numbers removed, two-column layouts in order. Scanned PDFs are read with OCR (English, Japanese). Pay per page.

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

## Pricing

Pay per event

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 Markdown & Text Converter for AI

Turn PDFs into clean Markdown or plain text that LLMs, RAG pipelines and search indexes can use right away.

- **Headings** become `#`, `##` and `###` lines, based on font size
- **Ruled tables** become Markdown tables (or tab-separated text)
- **Lists** stay lists, and lines wrapped by the PDF are joined back into paragraphs (hyphenated words too)
- **Running headers, footers and page numbers** that repeat on most pages are removed
- **Two-column layouts** (papers, magazines) are read column by column, not across
- **Japanese and other CJK text** is joined without stray spaces
- **Scanned PDFs** are read with OCR (English, Japanese or both), page by page, only where a page has no text layer
- **One row per page** option, with page numbers, for RAG chunking and citations
- Runs inside the Actor: no third-party API, no subscription, your PDFs are not sent anywhere else

Typical uses: feeding documents to ChatGPT, Claude or other LLMs, building RAG knowledge bases, indexing reports and manuals for search, and document pipelines run by AI agents.

### Input

```json
{
  "pdfUrls": ["https://example.com/annual-report.pdf"],
  "outputFormat": "markdown",
  "splitPages": false,
  "removeHeadersFooters": true,
  "includeTables": true,
  "ocr": true,
  "ocrLanguage": "eng",
  "maxPages": 0
}
```

PDFs must be direct links, up to 100 MB each. Use `maxPages` to convert only the first pages.

### Output

One row per PDF (or one per page with `splitPages`):

| field | example | meaning |
|---|---|---|
| `content` | `# Annual Report\n\n## Highlights…` | the Markdown or text |
| `contentUrl` | https://api.apify.com/v2/key-value-stores/…/records/00000-….md | the same content as a file |
| `title` | Annual Report 2025 | title from the PDF's metadata |
| `pageCount` / `pagesConverted` | 42 / 42 | pages in the PDF and pages converted |
| `ocrPages` | \[7, 8] | scanned pages that were read with OCR |
| `pagesWithoutText` | \[] | pages where no text was found, even with OCR |
| `pageNumber` | 3 | with `splitPages` only |
| `chargedPages` / `chargedOcrPages` | 40 / 2 | pages billed as text pages and as OCR pages |
| `error` | null | why a PDF could not be converted |

Very long documents (over 2 million characters) are returned only through `contentUrl`.

### Pricing

You pay per converted page with text, about **$1 per 1,000 pages**, with no per-document or start fee. Scanned pages read with OCR are billed per page at the OCR price shown on the Pricing tab. Pages where no text is found and PDFs that fail to download or open are free, and the run stops before it would go over your spending limit.

### FAQ

**Does it do OCR on scanned PDFs?** Yes. Pages that are only images are read with Tesseract OCR in the language you pick. Pages that already have text are never OCR'd, so a normal PDF costs the same as before. OCR works best on straight, clean scans; for large scanned documents, give the run 4 GB of memory to make OCR about four times faster. Turn `ocr` off to skip scanned pages for free.

**Are tables without lines detected?** Tables drawn with ruling lines are converted to Markdown tables. Tables laid out with spaces only come out as text lines.

**Are my PDFs stored anywhere?** Results are saved only in your own run's storage, which follows your Apify data retention settings.

**Can I process any file?** Only process images and documents you own or have permission to use. The Actor does not check rights for you.

**How do I call it from code or an AI agent?** Use the Apify API or the Apify MCP server with the input shown above; each dataset row contains the converted content.

### Credits

Built with [pdfplumber](https://github.com/jsvine/pdfplumber) and [pdfminer.six](https://github.com/pdfminer/pdfminer.six) (both MIT), [pypdfium2](https://github.com/pypdfium2-team/pypdfium2) (Apache-2.0 / BSD-3-Clause) and [Tesseract OCR](https://github.com/tesseract-ocr/tesseract) with its language models (Apache-2.0). Not affiliated with their authors. The sample PDF in the input form was made for this Actor.

# Actor input Schema

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

Direct links to PDF files (up to 100 MB each).

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

"markdown" keeps headings, lists and tables; "text" gives plain text with tab-separated tables.

## `splitPages` (type: `boolean`):

Output each page as its own dataset row with its page number, handy for RAG chunking and citations. Off: one row per PDF.

## `removeHeadersFooters` (type: `boolean`):

Drop text that repeats at the top or bottom of most pages, and lone page numbers.

## `includeTables` (type: `boolean`):

Turn ruled tables into Markdown tables.

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

Read pages that are only images (scans, photos of documents) with OCR. Pages that already have text are never OCR'd. Off: scanned pages are listed in pagesWithoutText and are free.

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

Language of the scanned text. "eng+jpn" handles documents that mix both, but is slower.

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

Convert only the first N pages of each PDF. 0 converts all pages.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://api.apify.com/v2/key-value-stores/bleIYCdyl2nnhq1os/records/product-catalog.pdf"
  ],
  "outputFormat": "markdown",
  "splitPages": false,
  "removeHeadersFooters": true,
  "includeTables": true,
  "ocr": true,
  "ocrLanguage": "eng",
  "maxPages": 0
}
```

# 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://api.apify.com/v2/key-value-stores/bleIYCdyl2nnhq1os/records/product-catalog.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("ohs999/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://api.apify.com/v2/key-value-stores/bleIYCdyl2nnhq1os/records/product-catalog.pdf"] }

# Run the Actor and wait for it to finish
run = client.actor("ohs999/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://api.apify.com/v2/key-value-stores/bleIYCdyl2nnhq1os/records/product-catalog.pdf"
  ]
}' |
apify call ohs999/pdf-to-markdown --silent --output-dataset

```

## MCP server setup

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