Spaces:
Runtime error
Runtime error
File size: 493 Bytes
849613e ef33305 849613e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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 |