Spaces:
Sleeping
Sleeping
| 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 | |