Spaces:
Running
Running
File size: 629 Bytes
7e4deac |
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 |
import fitz
from io import BytesIO
import streamlit as st
def ExtractPDFText(pdf):
content = ""
pdf_bytes = pdf.read()
try:
pdf_document = fitz.open("dummy.pdf", pdf_bytes)
# Iterate through pages and extract text
for page_number in range(pdf_document.page_count):
page = pdf_document[page_number]
text = page.get_text()
content += text
except Exception as e:
st.error(f"Error extracting text from PDF: {e}")
finally:
if "pdf_document" in locals():
pdf_document.close()
return content
|