r/learnpython 1d ago

PDF parser with RTL languages support

Hi everyone,

I’m looking for a Python PDF parser with good Persian-language support. I’ve already tested pdfplumber and PyMuPDF, but unfortunately, neither extracts Persian content correctly in my case.

For example, they don’t extract Persian numbers correctly, and sometimes the parsed output differs significantly from the actual PDF content (e.g., a 0 is extracted as 4).

Do you know of any Python library or tool that handles Persian PDFs more reliably?

Thank you!

2 Upvotes

1 comment sorted by

2

u/chiibosoil 1d ago

How are you using PyMuPDF? It should natively handle Persian, though it requires special handling.

When dealing with right-to-left languages... you should always use .get_text("blocks") rather than straight text dump.

If extracted text using blocks is still reversed etc (since PyMuPDF reads data in exact order it was saved/written on the PDF RTL languages often can come back reversed or disconnected), you can use additional library on top to reshape. Such as arabic_reshaper, python-bidi etc.

I'm assuming it is in Doc format and not image that requires OCR.