File size: 578 Bytes
a5c070f
7e4deac
4e28c13
7e4deac
 
 
 
 
 
a5c070f
 
 
 
 
 
7e4deac
 
 
 
4e28c13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import pdfplumber
import streamlit as st
from io import BytesIO  # Import BytesIO

def ExtractPDFText(pdf):
    content = ""
    pdf_bytes = pdf.read()

    try:
        # Using pdfplumber to read the PDF bytes
        with pdfplumber.open(BytesIO(pdf_bytes)) as pdf_document:
            # Iterate through pages and extract text
            for page in pdf_document.pages:
                text = page.extract_text()
                content += text if text else ""
        
    except Exception as e:
        st.error(f"Error extracting text from PDF: {e}")

    return content