DEV Community

Keerat Rashid
Keerat Rashid

Posted on Edited on

Why Arabic Invoice Extraction Is Harder Than You Think (and Why Gulf Buyers Have No Benchmark)

"RTL text, mixed Arabic/English lines, two digit systems, and stamps over the total. Why Arabic invoice extraction fails quietly, and why buyers can't compare vendors."

Invoice extraction looks like a solved problem. You upload a PDF and get back a vendor name, a date, line items, and a total. Demos are smooth, and vendors quote accuracy numbers in the high 90s.

Then you point the same system at a supplier invoice from Riyadh, Dubai, or Doha, and things get strange. The output looks plausible, so nobody notices. The failures are specific, mostly silent, and expensive when they reach the ledger.

This post walks through where Arabic invoices break typical pipelines, with a few code snippets, and then covers a second problem: buyers in the Gulf have no way to compare vendors on this task.

1. Right-to-left is more than flipping the page

Arabic runs right to left, but the hard parts are elsewhere.

It's cursive. Each letter takes a different form depending on whether it's initial, medial, final, or isolated. Some pairs fuse into ligatures, and diacritics may or may not be present. Models trained mostly on Latin script handle this poorly.

Reading order is a separate problem. Even with perfect character recognition, you have to decide what order to emit the characters in. Unicode stores text in logical order (the order you'd read or type it), while a display shows visual order. Digital PDFs often store glyphs in visual order, or as Arabic Presentation Forms rather than base letters, so naive text extraction can hand you a string that looks right on screen and is wrong in your database.

A cheap first defense is Unicode normalization:

import unicodedata

# Presentation-form glyphs (U+FB50–FDFF, U+FE70–FEFF) -> base letters
raw = "\ufe8e\ufedf\ufee3\ufeb8\ufe92\ufe8e\ufee7"  # as pulled from some PDFs
clean = unicodedata.normalize("NFKC", raw)
print(clean)
Enter fullscreen mode Exit fullscreen mode

NFKC maps presentation forms back to base letters, so the same word extracted from two PDFs compares equal. It does not fix reversed word order. For that you need to detect whether your extractor returned visual or logical order, and that varies by PDF producer.

One trap: libraries like arabic-reshaper plus python-bidi exist to prepare text for display. Run extracted text through them and you can end up storing display-order strings, which is the opposite of what you want in a database.

2. Mixed Arabic and English on the same line

Gulf invoices are often bilingual by design. A single line might contain:

  • an Arabic item description
  • a Latin product code
  • an English brand name
  • a quantity

Under the Unicode bidirectional algorithm, Latin text and digits embedded in an Arabic sentence run left to right inside a right-to-left paragraph. A parser that assumes one direction per line will split a description in the wrong place, attach a quantity to the wrong item, or reverse a part number like AB-1024-X.

Tables are worse. In an Arabic-layout invoice, columns progress right to left: item on the right, then quantity, unit price, and total moving leftward. Many bilingual templates mix conventions, with Arabic headers over English-ordered columns or the reverse. If your extractor maps fields by column position, it will swap quantity and unit price on some templates and nothing will throw an error.

The fix is to map columns by header meaning ("الكمية" / "Qty" / "Quantity" all mean quantity) rather than by index. Then cross-check, since quantity × unit_price ≈ line_total is a free validation that catches many swaps.

3. Two digit systems, plus the punctuation around them

An Arabic invoice may use Western digits (0–9), Eastern Arabic-Indic digits (٠–٩), or both on the same page. Dates might be in Western digits while the total is in Eastern. The same supplier may switch between documents. Persian and Urdu forms of some digits (۴ ۵ ۶ ۷) look different from the Arabic ones, which matters for suppliers across the wider region.

Python handles part of this for you:

>>> int("١٢٣")
123
>>> float("١٢٣٫٤٥")
ValueError: could not convert string to float: '١٢٣٫٤٥'
Enter fullscreen mode Exit fullscreen mode

The digits convert, but the Arabic decimal separator ٫ does not. And there's a thousands separator ٬ too. A normalizer has to handle all of it explicitly:

AR_DIGITS = str.maketrans("٠١٢٣٤٥٦٧٨٩۰۱۲۳۴۵۶۷۸۹", "0123456789" * 2)

def parse_amount(s: str) -> float:
    s = s.translate(AR_DIGITS)
    s = s.replace("٬", "").replace("٫", ".")
    s = s.replace("\u200f", "").replace("\u200e", "")  # strip bidi marks
    return float(s)

parse_amount("١٬٢٣٤٫٥٠")  # 1234.5
Enter fullscreen mode Exit fullscreen mode

This still isn't enough. Invoices also use , and . in both roles, so 1,234 might be one thousand two hundred thirty-four or 1.234 in a European-style format. Some use neither. In Gulf currencies like the Kuwaiti or Bahraini dinar and the Omani rial, amounts are conventionally written to three decimal places, so a "round to two decimals" assumption quietly corrupts totals.

Currency appears as a symbol, an abbreviation, or an Arabic word such as درهم or ريال. Dates may be Gregorian, Hijri, or both. A system that reads ١٢٣٫٤٥ as 12345 produces an error that looks entirely plausible downstream.

And tax registration numbers, invoice numbers, and amounts have no tolerance. A single wrong digit isn't a near miss. It's a wrong invoice.

4. Stamps, signatures, and handwriting

Many invoices in the region carry a company stamp, often with a signature scrawled across the printed text. Stamps are typically round or rectangular, in blue or red ink, with curved Arabic and English text. They're frequently placed directly over the total, the date, or the tax number, which are the fields that matter most.

This causes two distinct failures:

  1. Degraded recognition. Overlapping ink hurts OCR exactly where accuracy is critical.
  2. False fields. Stamps contain text that isn't invoice data, such as a company name, a registration number, or "PAID". A model can happily extract the stamp's registration number as the supplier's tax ID.

Then add scans, phone photos, skewed pages, and handwritten amendments. The clean-PDF assumption behind most demos stops holding.

5. Why buyers have no benchmark

All of this adds up to a buying problem rather than a research problem.

Public document-understanding datasets, and the accuracy claims built on them, are overwhelmingly English or Latin-script. When a vendor says "98% extraction accuracy", that number was almost certainly measured on documents that look nothing like a Gulf supplier invoice. It also rarely tells you:

  • which fields it covers
  • whether a wrong digit counts as an error (and whether it's counted per field, per character, or per document)
  • how it treats stamped, scanned, or bilingual pages
  • whether "accuracy" means the field was extracted or the field was correct

As far as I can tell, there's no widely accepted shared test set, field schema, or scoring method for Arabic and bilingual invoices. So every buyer runs their own proof of concept on a handful of hand-picked documents. Twenty samples can't tell you whether performance holds across two hundred thousand, and nothing lets you compare Vendor A to Vendor B.

Vendors are stuck in the mirror image of this. A vendor with a strong Arabic product can't publish a defensible number, because there's nothing agreed to measure against.

Until that changes, "Arabic support" is a claim buyers can't verify. The cost of finding out falls on the people who process the invoices, usually after something has been posted wrongly.

What would a benchmark need?

I don't have a finished answer, but the shape seems clear:

  • A shared, field-level schema: supplier, tax ID, invoice number, dates (with calendar type), currency, line items, tax, totals.
  • Strict scoring for identifiers and amounts: exact match, no partial credit for a mostly-right tax number.
  • Document strata reported separately: clean digital PDFs, scans, photos, stamped, bilingual-table layouts, mixed digit systems.
  • Realistic, consented or synthetic data, since real invoices carry sensitive commercial information.
  • Published error taxonomy: digit errors, field swaps, stamp-as-field, reading-order errors, so a score says how a system fails and not just how often.

Top comments (0)