> ## Documentation Index
> Fetch the complete documentation index at: https://docs.salmanahmad.online/llms.txt
> Use this file to discover all available pages before exploring further.

# RAG PDF Highlighter: Annotate PDFs for RAG Pipelines

> RAG PDF Highlighter locates text chunks in PDFs and returns an annotated copy with highlights applied — built for RAG pipelines.

RAG PDF Highlighter gives you a FastAPI microservice and an importable Python library that take the text chunks your retrieval pipeline surfaces and stamp them directly onto the source PDF — returning a fully annotated, highlighted document your users can read in seconds. Whether you call it over HTTP or import it as a library, you get the same stateless, Docker-ready service with no authentication overhead standing between you and highlighted PDFs.

<CardGroup cols={2}>
  <Card title="Introduction" icon="book-open" href="/introduction">
    Learn what RAG PDF Highlighter does and how it fits into your pipeline.
  </Card>

  <Card title="Quickstart" icon="rocket" href="/quickstart">
    Install the package and highlight your first PDF in under five minutes.
  </Card>

  <Card title="API Reference" icon="code" href="/api/overview">
    Explore the POST /highlight endpoint, request schema, and response format.
  </Card>

  <Card title="Guides" icon="map" href="/guides/rag-integration">
    Wire RAG PDF Highlighter into a LangChain or LlamaIndex retrieval pipeline.
  </Card>
</CardGroup>

## How It Works

<Steps>
  <Step title="Install the package">
    Add RAG PDF Highlighter to your project with a single command:

    ```bash theme={null}
    pip install rag-pdf-highlighter
    ```

    Or pull the pre-built Docker image to run it as a standalone microservice — no additional dependencies required.
  </Step>

  <Step title="Retrieve your chunks">
    Run your RAG pipeline as normal. Collect the `Document` objects your retriever returns — each one carries the matched `page_content` and a `metadata.page` value that tells the highlighter which page to search.
  </Step>

  <Step title="POST to /highlight">
    Send a single request with the URL of the source PDF and your list of `Document` objects. The service fetches the PDF, locates every chunk using a 3-tier matching strategy (exact → sentence → collapsed-whitespace fallback), and applies highlight annotations in one pass.

    ```python theme={null}
    import requests

    response = requests.post("http://localhost:8000/highlight", json={
        "pdf_url": "https://example.com/paper.pdf",
        "documents": [
            {"page_content": "Key finding from the paper.", "metadata": {"page": 3}}
        ]
    })

    with open("annotated.pdf", "wb") as f:
        f.write(response.content)
    ```
  </Step>

  <Step title="Serve the annotated PDF">
    The endpoint returns an `application/pdf` binary — the original document with every matched chunk highlighted and ready to display. Drop it straight into your document viewer, object store, or email it to your users.
  </Step>
</Steps>
