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 rag-pdf-highlighter
Or install from source:
git clone https://github.com/MuhammadSalmanAhmad/rag-pdf-highlighter.git
cd rag-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
Metadata
Release files for rag-pdf-highlighter 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rag_pdf_highlighter-0.1.1.tar.gz | 10.5 kB | Without provenance | Details for rag_pdf_highlighter-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rag_pdf_highlighter-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for rag_pdf_highlighter-0.1.1-py3-none-any.whl |
Total release size: 19.3 kB
Release files / rag_pdf_highlighter-0.1.1.tar.gz
| Download URL | rag_pdf_highlighter-0.1.1.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a2952e0f4662b3587d2eb2c389edc20a0d30ea6efa1b2d8066e371c6f6f09bad
|
|
BLAKE2b-256 checksum How to use checksums |
059332c46739cc8d936c10bf5b49b61813ff33906567972aacc9a14917d32ef7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Release files / rag_pdf_highlighter-0.1.1-py3-none-any.whl
| Download URL | rag_pdf_highlighter-0.1.1-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1655554bb36e9fe94d08577e3668ab32af58a4eab9a1173fa6f8520776ee812f
|
|
BLAKE2b-256 checksum How to use checksums |
d417ddf5f420029c22b8584be6724df30f55fbe72aae076b8b876ec77804ee34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Security for rag-pdf-highlighter 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.