Hebrew OCR: reading scanned Hebrew documents

Updated · Tested with Tesseract 5.5.0 with heb and eng data, pytesseract 0.3.13

In short

Install Tesseract's Hebrew data and read with lang="heb+eng". On a full page of Hebrew with numbers and an English name it made no errors in our test; heb alone got 2.8 percent of characters wrong, and the default English model returned nonsense. The text comes back in reading order. Short pages and digits need extra care.

Tesseract reads Hebrew well when it is told the page is Hebrew, and badly when it is not. We ran it three ways on a full page of Hebrew, hebrew-report-scan-300dpi.png: 126 words with a few numbers and one English company name.

Languages given to TesseractCharacters wrongWords wrong
None (English by default)NonsenseNonsense
heb2.8%2.4%
heb+eng0.0%0.0%

Install the Hebrew data

Shell
# Debian or Ubuntu
sudo apt-get install tesseract-ocr tesseract-ocr-heb
# macOS
brew install tesseract tesseract-lang

pip install pytesseract pillow

Read a Hebrew page

Python
import pytesseract
from PIL import Image

image = Image.open("hebrew-report-scan-300dpi.png")
text = pytesseract.image_to_string(image, lang="heb+eng")
print(text.split("\n")[0])
Output
דוח תפעול רבעוני

The text comes back in reading order, as you would type it. Nothing needs reversing, unlike text taken out of a Hebrew PDF, which is often stored backwards.

Why the language matters

Without lang, Tesseract reads the page with its English model and matches every Hebrew letter to the nearest Latin shape. The same title comes back as:

Output
19177 ‘71Y9N NIT

There is no error and no warning. If your results look like this, the language was not set.

Why heb+eng beats heb

Hebrew documents are rarely only Hebrew. They carry English names, email addresses and codes. With heb alone, Tesseract forces those into Hebrew letters and digits. On a short sample page, hebrew-scan-300dpi.png, the sentence with the English name came back as:

Output
החברה מוחזקת בידי 1+0 05חו0!0ס4 זססזהרו מאז שנת 2019.

With heb+eng the name is read correctly:

Output
החברה מוחזקת בידי Harbor Holdings Ltd מאז ...

Two details to handle afterwards. Tesseract wraps left-to-right runs inside Hebrew lines in invisible direction marks (U+200E and U+200F); strip them before you compare or search:

Python
import unicodedata

clean = "".join(ch for ch in text if unicodedata.category(ch) != "Cf")

And adding a language is not free. On that short page heb+eng read one Hebrew word as Latin letters, and both settings misread a number or two: 14 came back as 4. Check digits in the fields that matter.

Short pages are harder than full ones

The full page scored a clean result. The short page, with a few dozen words in a table, did not: a label lost its first word and a date lost a digit. OCR engines lean on context, and a line with two words gives them little. For forms and certificates:

  • scan at 300 DPI or more, never less;
  • crop to the field you need and read it with --psm 7 (one line);
  • for a field that holds only digits, allow only digits with -c tessedit_char_whitelist=0123456789-.

Detecting the language automatically

Tesseract can guess the script of a page (pytesseract.image_to_osd). It needs a fair amount of text to do it. For the full page it answered Hebrew. For the short page it answered Thai, with low confidence. If you know your documents are Hebrew, say so with lang and do not rely on detection.

Scanned PDFs

To OCR a PDF instead of an image, turn each page into an image first, as in how to OCR a scanned PDF in Python, or let OCRmyPDF do both and write a searchable PDF:

Shell
ocrmypdf -l heb+eng scan.pdf searchable.pdf

Hebrew OCR and 100sands

100sands does not do OCR. It reads PDFs and HTML files that contain text, so it cannot read the scans in this guide: a scanned PDF is refused with status 422 and the code NO_TEXT_IN_FILE, and an image file such as hebrew-report-scan-300dpi.png with 415 and UNSUPPORTED_FILE. For scanned Hebrew, use Tesseract with lang="heb+eng" as above.

Where it helps is Hebrew PDFs that do contain text. Those need no OCR at all: 100sands reads them from the file and returns each line in reading order, with no parameter to set. Hebrew PDF text extraction shows it.

Questions

Can Tesseract read Hebrew?

Yes. Install the Hebrew language data and pass lang="heb", or better lang="heb+eng" for documents that also contain English. On a clean full page at 300 DPI it made no errors in our test.

Why does my Hebrew OCR output look like random Latin letters?

No language was set, so Tesseract used its English model and matched each Hebrew letter to the nearest Latin shape. Pass the Hebrew language code.

Is OCR output for Hebrew reversed?

No. Tesseract returns Hebrew in reading order. It adds invisible direction marks around numbers and English words, which you should strip before comparing or searching.

Why are numbers wrong in my Hebrew OCR?

With the Hebrew model alone, digits and English are forced into Hebrew shapes. Use heb+eng, scan at 300 DPI, and for number-only fields restrict Tesseract to digits.

Try it on your own documents

A free plan every month, no credit card. See the Hebrew PDF text.

Start free