# PDF to RAG chunks with page numbers

**Use case:** 

Split a PDF into heading-aware chunks for RAG. Every chunk carries its start and end page and its heading path, so answers can cite the exact page and section. Set chunk size and overlap in tokens and load the JSON straight into a vector database.

## Input

```json
{
  "urls": [
    {
      "url": "https://nvlpubs.nist.gov/nistpubs/CSWP/NIST.CSWP.29.pdf"
    }
  ],
  "outputs": [
    "markdown",
    "chunks"
  ],
  "chunkSize": 512,
  "ocr": "auto",
  "ocrLanguage": "eng",
  "pageRange": "1-4",
  "tables": "markdown",
  "removeHeadersFooters": true,
  "maxPagesPerRun": 5000
}
```

## Output

```json
{
  "source": {
    "label": "Source",
    "format": "string"
  },
  "status": {
    "label": "Status",
    "format": "string"
  },
  "title": {
    "label": "Title",
    "format": "string"
  },
  "language": {
    "label": "Language",
    "format": "string"
  },
  "processedPages": {
    "label": "Processed pages",
    "format": "integer"
  },
  "ocrPages": {
    "label": "OCR pages",
    "format": "integer"
  },
  "wordCount": {
    "label": "Word count",
    "format": "integer"
  },
  "error": {
    "label": "Error message",
    "format": "string"
  },
  "markdown": {
    "label": "Markdown",
    "format": "string"
  }
}
```

## How it works

### 1. Sign up on Apify or log in

The PDF to Markdown Converter: OCR, Tables, RAG Actor is ready to run with the inputs already set for "PDF to RAG chunks with page numbers". [Sign up or log in](https://console.apify.com/create-task-from-example/ahFkkCX9BZYU9B5Ca) and you'll land in Apify Console with a copy of this exact task.

### 2. Start the "PDF to RAG chunks with page numbers" task

The PDF to Markdown Converter: OCR, Tables, RAG Actor will start running based on the input automatically. You can also change all the input fields, like PDF URLs, outputs, and more, to match your specific use case.

### 3. Receive the "PDF to RAG chunks with page numbers" output

Monitor the progress in real time. You will be notified as soon as your dataset is complete and ready for review. Each result includes data such as source, status, title, and more.

### 4. Integrate into your workflow

The final output is delivered in JSON, CSV, or Excel format, ready to be plugged into your workflow. You can also [run the "PDF to RAG chunks with page numbers" task via API](https://apify.com/jcwilk/pdf-to-markdown.md).

## FAQ

### What metadata does each PDF chunk have?

Each chunk from the PDF to RAG task has its text, start and end page, the heading path (such as 3 Model Architecture > 3.2 Attention), a character count and an approximate token count.

### How do I set chunk size and overlap?

Use chunkSize and chunkOverlap in the PDF to RAG task. Both are approximate tokens, where one token is about 4 characters. The defaults are 512 and 64.

### Can I chunk only some pages?

Yes. Set pageRange in the PDF to RAG task, for example 1-10 or 2,4,6-, and you only convert and pay for those pages.

### Can I run it from the API, n8n, Make or a schedule?

Yes. The PDF to RAG chunks task runs from the Apify API, schedules and webhooks, and from n8n, Make or Zapier, and returns JSON, CSV or Excel.

## About this Actor

This example demonstrates how to use [PDF to Markdown Converter: OCR, Tables, RAG](https://apify.com/jcwilk/pdf-to-markdown.md) with a specific input configuration. Visit the [Actor detail page](https://apify.com/jcwilk/pdf-to-markdown.md) to learn more, explore other use cases, and run it yourself.


## How to integrate an Actor?

This Task's input is already configured above. Use it as-is rather than inventing a new one.

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 full API examples (JavaScript, Python, CLI, MCP, OpenAPI), see this Task's Actor page: https://apify.com/jcwilk/pdf-to-markdown.md

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`).
