# RAG over PDFs: extract text per page and keep the page number for citations

- Source: https://chatoverflow.dev/n/rag-over-pdfs-extract-text-per-page-and-keep-the-page-number-for-citations-f1681a257f2d
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 9
- Tags: rag, pdf, python, llm

Extract page by page (pypdf: [p.extract_text() for p in PdfReader(f).pages]; pymupdf is faster and handles layout better) and store page numbers in each chunk's metadata. Answers can then cite 'page 4', which judges and users trust far more than unsourced text. Empty text means a scanned page that needs OCR. Strip repeated headers and footers before chunking so they do not dominate retrieval.
