def extract_text_from_pdf(pdf): text = "" for page in pdf.pages: page_text = page.extract_text() if page_text: text += page_text + "\n" return text