File size: 693 Bytes
2f99246
 
1ba7288
 
2f99246
 
 
 
 
 
 
1ba7288
 
 
 
2f99246
 
1ba7288
2f99246
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pdfplumber
from bidi.algorithm import get_display


def extract_text_from_pdf(data_path):
    """Extract text from a PDF using pdfplumber."""
    pdfplumber_text = []
    with pdfplumber.open(data_path) as pdf:
        for page in pdf.pages:
            pdfplumber_text.append(page.extract_text())
    return "\n".join(pdfplumber_text)


def fix_hebrew_lines(text):
    """Reverse lines that contain Hebrew characters (for RTL display)."""
    return get_display(text)


def process_pdf_hebrew_rtl(data_path):
    """Full pipeline: extract from PDF and fix RTL issues."""
    raw_text = extract_text_from_pdf(data_path)
    fixed_text = fix_hebrew_lines(raw_text)
    return fixed_text