# PDF to Markdown API: Word, Excel, PPTX for RAG (`jackalalpha/docs-to-markdown`) Actor

PDF to markdown API for RAG and LLMs. Converts PDF, Word (DOCX), Excel, PowerPoint, CSV and web pages from public links into clean markdown with token counts and optional ready-to-embed chunks. Pay only for documents that convert.

- **URL**: https://apify.com/jackalalpha/docs-to-markdown.md
- **Developed by:** [Jackal Alpha](https://apify.com/jackalalpha) (community)
- **Categories:** AI, Developer tools
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 documents converted

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/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 API: Word, Excel, PPTX for RAG

By Jackal Alpha.

This PDF to markdown converter takes public links and returns clean markdown for LLM and RAG pipelines. It reads PDF, Word (.docx), Excel (.xlsx), PowerPoint (.pptx), CSV and web pages, so one Actor replaces a PDF tool plus a DOCX tool plus a spreadsheet tool. Each document becomes one dataset record with the markdown, detected type, title, page or sheet count, character count and approximate token count. Set a chunk size and the record also carries ready-to-embed chunks split at headings and paragraphs. Price: $0.003 per converted document ($3 per 1,000), and failed documents are free. Text only: no OCR, so a scanned PDF returns a clear, uncharged error.

**OCR is optional.** A scanned PDF with no text layer returns a clear `SCANNED_PDF` error, uncharged. Set `ocr` to `true` to read those pages with OCR (English or Arabic, slower, not exact).

**What it does not do:** no password-protected files, no old binary Office files (`.doc`, `.xls`, `.ppt`), no OCR of pictures inside Word files, and OCR does not rebuild tables.

### Convert PDF, DOCX and XLSX to markdown: supported formats

| Format | How it is converted |
|---|---|
| PDF | Text layer, page by page. Tables are found from the position of the text and written as markdown tables. Arabic and other right-to-left text is put back in reading order. Pages with no text layer are listed in `warnings`, or read with OCR when `ocr` is on. Blank lines are kept where the layout shows a paragraph gap. Title comes from the PDF's metadata. |
| DOCX | Headings, nested lists, bold and italic, links and tables become markdown. Merged table cells are laid out on a plain grid. Each picture becomes a markdown image link with its alt text (`imageMode`). |
| XLSX | Every sheet becomes a markdown table under a `##` heading with the sheet name. Dates are written as ISO dates. |
| CSV / TSV | One table. The delimiter (comma, semicolon, tab or pipe) is detected. |
| PPTX | Text of each slide under `## Slide N`, in slide order. Speaker notes are not included. |
| HTML | The main article content is extracted (navigation, footers and scripts are dropped) and converted. If no article is found, the whole body is used. Scripts are never run. |
| Markdown, plain text | Passed through, with line endings tidied. |

The type is detected from the file content first, then the content type and file name. A `.pdf` link that serves HTML is converted as HTML.

### Input: chunking documents for RAG

| Field | Type | Default | Meaning |
|---|---|---|---|
| `urls` | list of strings | three small public documents | Public http(s) links. Repeats are skipped. |
| `recordKeys` | list of strings | none | Keys of files you uploaded to a key-value store. |
| `keyValueStoreId` | string | this run's default store | Store that holds those keys. |
| `maxPagesPerDocument` | integer | `500` (max 5000) | Convert only the first N PDF pages or PPTX slides. `0` or empty uses 500. |
| `maxRowsPerSheet` | integer | `1000` | Data rows kept per sheet or CSV, after the header. Max 100000; `0` also means 100000. |
| `maxFileSizeMb` | integer | `25` | Larger files are rejected (1-50). |
| `chunkSize` | integer | `0` (off) | Also return chunks of at most this many characters. |
| `chunkOverlap` | integer | `0` | Characters repeated from the end of the previous chunk. Capped at half of `chunkSize`. |
| `includeMetadataOnly` | boolean | `false` | Leave out `markdown` and `chunks`; keep type, title, counts and sizes. Converted documents are still charged. |
| `ocr` | boolean | `false` | Read PDF pages that have no text layer with OCR. |
| `ocrLanguages` | list | `["eng"]` | `eng` and/or `ara`. For Arabic documents use `["ara"]` alone: mixing languages lowers accuracy. |
| `ocrMaxPages` | integer | `20` | Most pages OCR reads per document. |
| `imageMode` | string | `placeholder` | Word pictures: `placeholder` (`![alt](image-1.png)`), `inline` (data URI) or `drop`. |
| `concurrency` | integer | `4` | Documents converted in parallel (1-10). |
| `requestTimeoutSecs` | integer | `60` | Download time limit per document (5-300). |

If neither `urls` nor `recordKeys` has an entry, the run fails.

### Output

One record per document, always with the same fields:

```json
{
  "url": "https://www.irs.gov/pub/irs-pdf/fw9.pdf",
  "recordKey": null,
  "finalUrl": "https://www.irs.gov/pub/irs-pdf/fw9.pdf",
  "type": "pdf",
  "title": "Form W-9 (Rev. March 2024)",
  "pageCount": 6,
  "sheetCount": null,
  "sizeBytes": 140815,
  "characters": 37977,
  "approxTokens": 9495,
  "truncated": false,
  "markdown": "Form W-9\n(Rev. March 2024)\n\nRequest for Taxpayer\nIdentification Number and Certification\n...",
  "chunks": [
    { "index": 0, "heading": null, "characters": 1480, "approxTokens": 370, "text": "Form W-9 ..." }
  ],
  "error": null
}
```

- `approxTokens` is characters divided by 4, rounded up. It is a rough guide for budgeting, not an exact count for any one model.
- `pageCount` is pages for PDF and slides for PPTX, otherwise `null`. `sheetCount` is set for XLSX and CSV.
- `truncated` is `true` when `maxPagesPerDocument` or `maxRowsPerSheet` cut the document short.
- `chunks` is `null` unless `chunkSize` is above 0. Each chunk starts at a heading when it can, keeps a code block together when it fits, and stays within `chunkSize` characters (overlap text is added on top, up to `chunkOverlap`). `heading` is the nearest heading above the chunk's start.
- Failed documents have `error` set and everything else `null`. Examples: `HTTP 404.`, `SCANNED_PDF: no text layer found, this looks like a scanned or image-only PDF. Set "ocr" to true to read it with OCR (slower).`, `Password-protected PDFs are not supported.`

### Use cases

- Prepare PDFs and Word files for a RAG pipeline or a vector database.
- Turn spreadsheets and slide decks into markdown tables and text for an LLM prompt.
- Estimate token counts for a document set before sending it to a model.
- Run the same conversion on a schedule or from your own code through the API.

### How to run it from the API

Send links and get markdown back in one request. Replace `YOUR_API_TOKEN` with your Apify token.

```bash
curl -X POST "https://api.apify.com/v2/acts/jackalalpha~docs-to-markdown/run-sync-get-dataset-items?token=YOUR_API_TOKEN"   -H "Content-Type: application/json"   -d '{"urls": ["https://www.irs.gov/pub/irs-pdf/fw9.pdf"], "chunkSize": 1500, "chunkOverlap": 150}'
```

The response is a JSON array with one record per document, in the format shown under Output.

### Pricing

Pay per event: **$0.003 per successfully converted document** (event `document-converted`), so 1,000 documents cost $3.00.

Worked example: you send 500 links. 470 convert, 25 return HTTP 404 and 5 are scanned PDFs. You pay for 470 documents: 470 x $0.003 = **$1.41**. The 30 error records are free.

Chunking and `includeMetadataOnly` do not change the price. If you set a maximum cost per run and it is reached, the run stops cleanly, delivers only documents that were paid for, and the status message says it stopped at the charge limit and how many documents were not processed.

### Safety and limits

- Only `http` and `https` links are accepted. Links with embedded credentials are refused.
- Links that point at private, loopback or link-local addresses (for example `localhost`, `10.x.x.x`, `192.168.x.x`, `169.254.169.254`) are refused. The check runs on the resolved address at connection time, including every redirect, so a public name that redirects or resolves to an internal address is refused too. Up to 5 redirects are followed.
- The size limit is enforced while downloading, on the decompressed data. Downloads time out after `requestTimeoutSecs`.
- Pages that need a login, cookies or JavaScript to show their content are not supported. You get whatever the plain server response contains.
- Memory: very large PDFs or spreadsheets (near the 50 MB ceiling) need more run memory. Lower the file size limit or the concurrency if a run runs out.
- PDF text comes in reading order as the file stores it. Tables are rebuilt from text positions: simple grids work well, tables with merged cells or text that wraps inside cells may split or merge columns. Figure labels can occasionally look like a table.
- OCR text can contain mistakes (Arabic more than English), loses layout and tables, and runs about 2 to 5 seconds per page. Language data is bundled, nothing is downloaded at run time.

### Libraries and licences

| Purpose | Library | Licence |
|---|---|---|
| PDF text | `unpdf` (bundles Mozilla pdf.js) | MIT (pdf.js: Apache-2.0) |
| DOCX | `mammoth` | BSD-2-Clause |
| XLSX | `read-excel-file` | MIT |
| PPTX and DOCX metadata | `jszip` | MIT (dual-licensed MIT or GPL-3.0; used under MIT) |
| HTML parsing | `jsdom` | MIT |
| HTML main content | `@mozilla/readability` | Apache-2.0 |
| OCR | `tesseract.js`, `@tesseract.js-data/eng`, `@tesseract.js-data/ara` | Apache-2.0 |
| PDF page images for OCR | `@napi-rs/canvas` | MIT |
| HTML and DOCX to markdown | `turndown`, `turndown-plugin-gfm` | MIT |
| Actor runtime | `apify` | Apache-2.0 |

CSV parsing and PPTX text extraction are written in this Actor. No native binaries and no headless browser are used.

### FAQ

**How do I convert a PDF to markdown for an LLM?** Put the PDF link in `urls` and read the `markdown` field of the record. Set `chunkSize` to also get chunks.

**Which file types are supported?** PDF, DOCX, XLSX, CSV and TSV, PPTX, HTML, Markdown and plain text. See the formats table.

**How much does it cost?** $0.003 per converted document, so 1,000 documents cost $3.00. Failed documents are free.

**Why did my PDF fail with "SCANNED_PDF"?** It is made of page images (a scan or photo). Set `ocr` to `true` to read it with OCR, or run your own OCR first. A failure here is free.

**Can I convert files I do not have a public link for?** Yes. Upload them to a key-value store and list the keys in `recordKeys`.

**How do I get chunks for a vector database?** Set `chunkSize` (for example 1500) and `chunkOverlap` (for example 150) and read the `chunks` array of each record.

**Why is a spreadsheet cut off?** Sheets are capped at `maxRowsPerSheet` data rows (1000 by default) so one huge file does not flood your pipeline. Raise it or set 0 for no cap.

**Why are there fewer records than links?** Repeated links are skipped. If you set a maximum cost per run and it ran out, the status message shows how many were not processed.

**Does it keep my documents?** It keeps nothing beyond the run's own dataset. Files are processed in memory.

**Input limits.** One run accepts up to 1000 `urls` and 1000 `recordKeys` per run, 500 pages per document by default (max 5000), 25 MB per file by default (max 50), 100000 rows per sheet at most. Above that the run stops at once with a clear message; split the work into several runs.

# Actor input Schema

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

Public http(s) links to documents, one per line: PDF, DOCX, XLSX, PPTX, CSV, HTML, Markdown or plain text. Links to private or internal addresses are refused.

## `recordKeys` (type: `array`):

Keys of files you uploaded to a key-value store. The file type is taken from the content and the key extension (for example report.pdf).

## `keyValueStoreId` (type: `string`):

ID or name of the store that holds the record keys above. Leave empty to use this run's default store.

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

Convert only the first N pages (PDF) or slides (PPTX). Default 500, maximum 5000. Documents cut short are marked truncated.

## `maxRowsPerSheet` (type: `integer`):

Rows kept per sheet or CSV file after the header row. Extra rows are dropped and the document is marked truncated. 0 means the maximum, 100000.

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

Files larger than this are rejected while downloading, without being charged.

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

Set above 0 to also return the markdown split into chunks of at most this many characters, cut at headings and paragraphs. 0 turns chunking off. About 4 characters make 1 token.

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

Characters repeated from the end of the previous chunk at the start of the next one. Capped at half the chunk size.

## `includeMetadataOnly` (type: `boolean`):

Leave out the markdown and chunks and return only type, title, counts and sizes. Converted documents are still charged.

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

Read pages that have no text layer (scanned or image-only PDFs) with OCR. Slower and less exact than real text, and tables in scans are not rebuilt. Off by default: a scanned PDF then fails with a clear error and is not charged.

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

Languages of the scanned text. Use Arabic alone for Arabic documents: mixing languages lowers accuracy.

## `ocrMaxPages` (type: `integer`):

OCR is slow, so only the first N pages without text are read. The rest stay empty and the document is marked truncated.

## `imageMode` (type: `string`):

Placeholder keeps each picture's position and alt text as a markdown image link (image-1.png). Inline embeds the picture as a data URI. Drop removes pictures.

## `concurrency` (type: `integer`):

Documents converted in parallel.

## `requestTimeoutSecs` (type: `integer`):

Maximum time to download one document.

## Actor input object example

```json
{
  "urls": [
    "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
    "https://www.w3.org/Style/Examples/011/firstcss.en.html",
    "https://www.irs.gov/pub/irs-pdf/fw9.pdf"
  ],
  "maxPagesPerDocument": 500,
  "maxRowsPerSheet": 1000,
  "maxFileSizeMb": 25,
  "chunkSize": 0,
  "chunkOverlap": 0,
  "includeMetadataOnly": false,
  "ocr": false,
  "ocrLanguages": [
    "eng"
  ],
  "ocrMaxPages": 20,
  "imageMode": "placeholder",
  "concurrency": 4,
  "requestTimeoutSecs": 60
}
```

# 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 = {
    "urls": [
        "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
        "https://www.w3.org/Style/Examples/011/firstcss.en.html",
        "https://www.irs.gov/pub/irs-pdf/fw9.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("jackalalpha/docs-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",
        "https://www.w3.org/Style/Examples/011/firstcss.en.html",
        "https://www.irs.gov/pub/irs-pdf/fw9.pdf",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("jackalalpha/docs-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",
    "https://www.w3.org/Style/Examples/011/firstcss.en.html",
    "https://www.irs.gov/pub/irs-pdf/fw9.pdf"
  ]
}' |
apify call jackalalpha/docs-to-markdown --silent --output-dataset

```

## MCP server setup

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