resume-screening-rag / src /pdf_utils.py
btran299's picture
Update src/pdf_utils.py
ef33305 verified
Raw History Blame Contribute Delete
493 Bytes
from __future__ import annotations
import fitz # PyMuPDF
def extract_pdf_text_by_page(pdf_bytes: bytes) -> list[dict]:
"""
Returns: [{"page": 1, "text": "..."},...]
"""
doc = fitz.open(stream=pdf_bytes, filetype="pdf")
pages = []
for i in range(len(doc)):
page = doc[i]
text = page.get_text("text") or ""
text = " ".join(text.split()) # normalize whitespace
pages.append({"page": i + 1, "text": text})
doc.close()
return pages