# AI Document Extractor: PDF, DOCX to Markdown + RAG chunks (`jobdata_labs/ai-document-extractor`) Actor

Convert PDF, Word (DOCX) and text files to clean Markdown or text, split into RAG-ready chunks with page numbers and token estimates. Headings rebuilt from PDFs, scanned PDFs flagged, failed files free.

- **URL**: https://apify.com/jobdata_labs/ai-document-extractor.md
- **Developed by:** [Momi](https://apify.com/jobdata_labs) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 documents

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

## AI Document Extractor — PDF, DOCX & TXT to Markdown + RAG chunks

Turn **PDF, Word (DOCX) and text files into clean Markdown or plain text**, already **split into chunks for RAG, embeddings and LLM prompts**. Paste file URLs, get structured JSON back — no API keys, no code.

### What you get for each document

- **Markdown with structure**: headings are rebuilt from font sizes in PDFs (and kept from DOCX), so LLMs see sections, not a wall of text.
- **RAG-ready chunks**: configurable size and overlap, each with `startPage` / `endPage` (PDF) and an `approxTokens` estimate — ready for your vector database.
- **Metadata**: title, author, creation date (when present), pages, words, characters, approximate tokens.
- **Scanned PDF detection**: if most pages contain no text layer, the item is flagged `needsOcr: true` instead of silently returning empty text.
- **Clean errors**: broken links, HTML pages or unsupported files return an item with `error` — and are **not charged**.

### Supported files

| Type | Notes |
|---|---|
| PDF | Text-based PDFs. Line joining, de-hyphenation, heading detection, rotated margin text removed. |
| DOCX | Word 2007+ documents, headings and bold kept. Tables are flattened to text. |
| TXT / MD | UTF-8 text; Markdown headings are recognized. |

Max 50 MB per file. Use **direct file links** (a URL that downloads the file), not web pages.

### Output example

```json
{
  "url": "https://arxiv.org/pdf/1706.03762",
  "fileType": "pdf",
  "title": "Attention Is All You Need",
  "pages": 15,
  "words": 6164,
  "approxTokens": 10250,
  "needsOcr": false,
  "content": "# Attention Is All You Need\n\n...",
  "chunks": [
    { "index": 0, "text": "...", "characters": 1480, "approxTokens": 370, "startPage": 1, "endPage": 1 }
  ]
}
```

### Use cases

- **RAG pipelines**: feed chunks straight into Pinecone, Weaviate, Qdrant, pgvector or any embedding API.
- **LLM prompts**: summarize contracts, papers, manuals or reports with structure preserved.
- **Bulk conversion**: convert hundreds of PDFs/DOCX to Markdown for a knowledge base or a static site.
- **Automations**: call it from Make, Zapier, n8n or the Apify API whenever a new document arrives.

### Pricing

Pay per event: a small fee **per document** plus **per page** (for DOCX/TXT one "page" = 3,000 characters). Failed downloads and unsupported files are free. Limit pages with *Max pages per PDF* and total spend with *Maximum cost per run*.

### Limits

- No OCR in this version: scanned PDFs are detected and flagged, not transcribed.
- Complex layouts (multi-column pages, tables) are extracted as readable text, not as tables.
- Files are processed only for this run and are not stored beyond your own run storage.

### Feedback

Need OCR, PPTX, XLSX or table extraction? Open an issue on the *Issues* tab — features are prioritized by requests.

# Actor input Schema

## `sources` (type: `array`):

Direct links to PDF, DOCX, TXT or MD files (one per line). Web pages (HTML) are not supported: use a link that downloads the file.

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

Markdown keeps the document structure (headings) for LLMs; plain text has no markup.

## `chunkSize` (type: `integer`):

Split each document into RAG-ready chunks of about this many characters (~4 characters per token). 0 = no chunks.

## `chunkOverlap` (type: `integer`):

Characters repeated at the start of each chunk from the end of the previous one, to keep context.

## `includeFullText` (type: `boolean`):

Add the whole extracted document in the content field, besides the chunks.

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

0 = all pages. Useful to process only the first pages of long PDFs (you are charged only for processed pages).

## `maxConcurrency` (type: `integer`):

How many documents are downloaded and processed at the same time.

## Actor input object example

```json
{
  "sources": [
    "https://arxiv.org/pdf/1706.03762"
  ],
  "outputFormat": "markdown",
  "chunkSize": 1500,
  "chunkOverlap": 150,
  "includeFullText": true,
  "maxPagesPerDocument": 0,
  "maxConcurrency": 4
}
```

# 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 = {
    "sources": [
        "https://arxiv.org/pdf/1706.03762"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("jobdata_labs/ai-document-extractor").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 = { "sources": ["https://arxiv.org/pdf/1706.03762"] }

# Run the Actor and wait for it to finish
run = client.actor("jobdata_labs/ai-document-extractor").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 '{
  "sources": [
    "https://arxiv.org/pdf/1706.03762"
  ]
}' |
apify call jobdata_labs/ai-document-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,jobdata_labs/ai-document-extractor"
        }
    }
}
```

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/1wtHKwb76GngCbYpv/builds/GNFEyVpTTtbPY0qM0/openapi.json
