""" 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()