Spaces:
Sleeping
Sleeping
File size: 1,000 Bytes
c7fb8cf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | """
parser.py
---------
Extracts raw text from PDF files using PyPDF2.
Falls back gracefully if a page has no extractable text.
"""
import io
import PyPDF2
def extract_text_from_pdf(file_bytes: bytes) -> str:
"""
Given the raw bytes of a PDF, return all extracted text as a single string.
Each page is separated by a newline for downstream parsing.
"""
text_parts = []
try:
reader = PyPDF2.PdfReader(io.BytesIO(file_bytes))
for page in reader.pages:
page_text = page.extract_text()
if page_text:
text_parts.append(page_text.strip())
except Exception as e:
# If parsing fails entirely, return empty string and let caller handle it
print(f"[Parser] Error reading PDF: {e}")
return "\n".join(text_parts)
def extract_text_from_string(text: str) -> str:
"""
Pass-through for plain text resumes (optional text-paste input).
Applies light normalization.
"""
return text.strip()
|