File size: 498 Bytes
fe6855c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import pytesseract
import pdfplumber
from PIL import Image

def extract_text_from_pdf(pdf_path: str) -> str:
    """Extracts text from a PDF file."""
    text = ""
    with pdfplumber.open(pdf_path) as pdf:
        for page in pdf.pages:
            text += page.extract_text() + "\n"
    return text.strip()

def extract_text_from_image(image_path: str) -> str:
    """Extracts text from an image file using OCR."""
    image = Image.open(image_path)
    return pytesseract.image_to_string(image)