Highlight text chunks in PDFs – a FastAPI microservice for RAG pipelines
Project description
RAG PDF Highlighter
Highlight text chunks inside PDF documents — built for RAG pipelines.
Given a PDF URL and a list of text chunks (with page numbers), this service locates each chunk in the PDF and returns an annotated copy with highlights applied.
Features
- 3-tier text matching — exact → sentence → collapsed-whitespace fallback
- Async PDF download — non-blocking I/O via
httpx - Stateless — temp files are cleaned up after every request
- Docker-ready — single-command container deployment
- Library-friendly — core logic raises plain Python exceptions, no FastAPI dependency required
Installation
pip install callisto-pdf-highlighter
Or install from source:
git clone https://github.com/RipeSeed/calli-pdf-highlighter-.git
cd calli-pdf-highlighter-
pip install -e ".[dev]"
Quick Start
As a microservice
uvicorn rag_pdf_highlighter.main:app --host 0.0.0.0 --port 8000
Then send a POST request:
curl -X POST http://localhost:8000/highlight \
-H "Content-Type: application/json" \
-d '{
"pdf_url": "https://example.com/report.pdf",
"documents": [
{
"page_content": "Text to highlight in the PDF",
"metadata": {"page": 0}
}
]
}' \
--output highlighted.pdf
With Docker
docker build -t rag-pdf-highlighter .
docker run -p 8000:8000 rag-pdf-highlighter
As a library
from langchain_core.documents import Document
from rag_pdf_highlighter.utils.pdf_helpers import highlight_chunks_in_pdf
documents = [
Document(page_content="Text to find", metadata={"page": 0}),
]
output_path = highlight_chunks_in_pdf(
pdf_path="./report.pdf",
documents=documents,
)
print(f"Highlighted PDF saved to: {output_path}")
API Reference
GET /
Health check endpoint.
POST /highlight
| Field | Type | Description |
|---|---|---|
pdf_url |
string |
URL of the PDF to highlight |
documents |
array |
List of {page_content, metadata} objects |
documents[].page_content |
string |
The text chunk to locate and highlight |
documents[].metadata.page |
int |
Zero-indexed page number |
Returns: The highlighted PDF file (application/pdf).
Development
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Lint
ruff check src/ test/
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rag_pdf_highlighter-0.1.0.tar.gz.
File metadata
- Download URL: rag_pdf_highlighter-0.1.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad5ba27e1b388262d8dda2acef52de381827f46b97fa3d8f71887a5caa158090
|
|
| MD5 |
f0d616da6675008e970552c58f4d2c07
|
|
| BLAKE2b-256 |
d35f13b0b90a209430f2c3793e5e07d1bcb64741a88fc99b3d8e2f11eb9a26eb
|
File details
Details for the file rag_pdf_highlighter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rag_pdf_highlighter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bb36211c4d48328621f4fec14e5fb36718c608a8e957b8f556ebe939586d7af
|
|
| MD5 |
99e225d5fb580a1f0a57035bf1ed03a2
|
|
| BLAKE2b-256 |
e377a90f639aadfa20f3fc8b8c21cc7f9e999f0601bf345d15729aa8bbeeffa1
|