# PDF to Markdown + OCR — Structured Document Extraction (`kaz_kakyo/pdf-structured-ocr`) Actor

Convert public PDF URLs into clean structured Markdown. Born-digital pages extract natively; scanned or image-only pages are recovered by a built-in OCR engine — no key or setup required. Per-page mode, confidence and partialFailures for PDF to Markdown and scanned PDF extraction pipelines.

- **URL**: https://apify.com/kaz\_kakyo/pdf-structured-ocr.md
- **Developed by:** [Heim AI](https://apify.com/kaz_kakyo) (community)
- **Categories:** Developer tools, AI, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 native text pages

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## PDF to Markdown + OCR — Structured Document Extraction

**Public PDF URL in → structured Markdown out.** Born-digital pages extract natively; scanned / image-only pages go through a **managed OCR engine**. Built for **PDF to Markdown**, **PDF OCR API**, **scanned PDF extraction**, and structured document data pipelines (MCP / API / schedule).

| | |
|---|---|
| **Actor id** | `kaz_kakyo/pdf-structured-ocr` |
| **Minimal input** | `{ "pdfUrls": ["https://…/file.pdf"] }` |
| **Cost** | **$0.001**/native page · **$0.012**/OCR page · **$0.005**/document manifest · $0.00005 start |
| **Output** | `type: "page"` rows + one `type: "manifest"` per document (or `type: "error"`) |

### Call it (MCP / API)

```json
{
  "actor": "kaz_kakyo/pdf-structured-ocr",
  "input": {
    "pdfUrls": ["https://example.com/report.pdf"],
    "ocr": "auto"
  }
}
```

OCR is **included** — no setup, no key required. Native-text pages always succeed; if a page needs OCR and OCR capacity is unavailable, it is marked `mode: "unavailable"` and listed in `partialFailures`. Very large or image-heavy pages may return `unavailable` rather than being silently truncated. **Billed only for pages actually delivered.**

Because OCR capacity is shared across all users, each run caps OCR-billable pages (`maxOcrPages`, default 100, hard ceiling 200). **Native (born-digital) extraction is unaffected by the cap and consumes no OCR capacity.**

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

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('kaz_kakyo/pdf-structured-ocr').call(
  {
    pdfUrls: ['https://example.com/report.pdf'],
    ocr: 'auto',
    ocrMaxWaitSecs: 300,
    maxPages: 50,
  },
  { maxTotalChargeUsd: 1.0 },
);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
const manifest = items.find((i) => i.type === 'manifest');
```

### Output contract

**Page row** (charged only when `mode` is `native` or `ocr`):

```json
{
  "type": "page",
  "url": "https://example.com/report.pdf",
  "pageNumber": 1,
  "mode": "native",
  "confidence": null,
  "markdown": "## Introduction\n\n…",
  "textCharCount": 1842
}
```

| `mode` | Meaning |
|---|---|
| `native` | Born-digital text extracted locally |
| `ocr` | Page recovered by the managed OCR engine |
| `unavailable` | Needed OCR but capacity unavailable / OCR failed / budget exhausted — **never charged** |

**Manifest** (charged only when ≥1 page was delivered):

```json
{
  "type": "manifest",
  "url": "https://example.com/report.pdf",
  "pageCount": 12,
  "pagesDelivered": 12,
  "markdown": "<!-- page 1 (native) -->\n\n…",
  "pages": [{ "pageNumber": 1, "mode": "native", "confidence": null }],
  "partialFailures": []
}
```

### Pricing

| Event | Price | When |
|---|---|---|
| `native-page-delivered` | **$0.001** | Each saved native-text page |
| `ocr-page-delivered` | **$0.012** | Each saved OCR page |
| `document-manifest-delivered` | **$0.005** | Final manifest, only if ≥1 page delivered |
| `apify-actor-start` | **$0.00005** | Per run |
| Default dataset item | **$0** | Never billed separately |

Charge order: budget-check → save dataset row → `Actor.charge()`. Unavailable / error rows are never billed. Cap spend with `maxTotalChargeUsd`.

### Input

| Field | Notes |
|---|---|
| `pdfUrls` / `pdfUrl` | Public http(s) PDF links only |
| `maxPages` | Default 50 (hard cap 500) |
| `ocr` | `auto` (default) · `never` · `always` |
| `maxOcrPages` | Default 100 (hard ceiling 200); per-run OCR page cap |
| `ocrMaxWaitSecs` | Default 300 (max 900); OCR timeout → `ocr_timeout`, uncharged |

Private / localhost / link-local / RFC1918 targets are rejected (SSRF guard, enforced at connect time and on every redirect hop). File size cap: 50 MB, enforced while streaming. PDFs are fetched over direct egress only — no proxy, because a proxy cannot enforce the connect-time address ACL. OCR processes the already-fetched PDF bytes; the source is never re-fetched.

### Why this one

- **Structured Markdown**, not a blob of OCR text — headings and crude tables from layout when native text exists.
- **Page-level honesty**: every page reports `mode` + `confidence`; gaps go in `partialFailures`.
- **OCR only when needed** (`auto`) so born-digital PDFs stay cheap.
- **Billed only for pages actually delivered** — timeouts, failures, and capacity limits never charge OCR pages.

# Actor input Schema

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

Public https links to PDF files. Private/localhost/link-local/RFC1918 targets are rejected (SSRF guard). One document processed per URL.

## `pdfUrl` (type: `string`):

Optional single public PDF URL. Merged with `pdfUrls` when both are set.

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

Cap pages processed per document (default 50). Extra pages are skipped and listed in `partialFailures`.

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

`auto` (default): OCR only low-text / image-only / rotated pages. `always`: OCR every page via the managed OCR engine. `never`: native extraction only.

## `maxOcrPages` (type: `integer`):

Caps how many pages this run may send to OCR. Default 100, hard ceiling 200. Protects shared OCR capacity across users. Native (born-digital) extraction is unaffected.

## `ocrMaxWaitSecs` (type: `integer`):

Maximum time to wait for an OCR job to finish (poll every 5s). Default 300, max 900. On timeout, OCR-routed pages are marked `unavailable` (reason `ocr_timeout`) and not charged.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
  ],
  "maxPages": 50,
  "ocr": "auto",
  "maxOcrPages": 100,
  "ocrMaxWaitSecs": 300
}
```

# Actor output Schema

## `overview` (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("kaz_kakyo/pdf-structured-ocr").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("kaz_kakyo/pdf-structured-ocr").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).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 kaz_kakyo/pdf-structured-ocr --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=kaz_kakyo/pdf-structured-ocr",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/acts/VQGo8957d1vuCK5mz/builds/x2xTjmhesM5nv7an8/openapi.json
