OCR for scanned PDFs and images, including Arabic in the right order
Two things annoy me about OCR on PDFs. The first is paying OCR prices for pages that never needed OCR. The second is Arabic text that comes back with the words in the wrong order, so you cannot search it or hand it to a language model. This post covers an Apify actor I publish as cyrus_1 that deals with both. I built it with an AI-assisted workflow: a small team of AI agents builds, tests and…
This Apify actor, called cyrus_1, tackles two issues related to OCR (Optical Character Recognition) on PDFs and images, including Arabic text. The first issue is the cost of paying for OCR pages that do not require OCR. The second issue is the incorrect order of Arabic text after OCR, making it unusable for searching or handing to a language model.
The actor uses the RapidOCR with PaddleOCR models, running on a CPU inside the actor, and performs image OCR on PNG, JPEG, WebP, or TIFF images, as well as PDFs. It returns one JSON row per image, per TIFF frame, and per PDF page. Each row contains joined text, line confidence, and a four-corner box. The engine operates without any login, key, or proxy.
The actor checks each PDF page to see if it already has a text layer with at least 40 letters or digits. If it does, the actor reads that text and skips the OCR process. Otherwise, it performs OCR on pages without text layers. The OCR pricing is significantly lower for pages read from their text layer ($0.001 per 1,000 pages) compared to pages read by OCR ($0.004 per 1,000 pages).
For scans and images, the actor performs OCR on pages without text layers, producing rows with line confidence, boxes, and language information. The text is returned in a logical order, which can be used directly for searching or a language model without further processing. For Arabic language, the actor uses the appropriate language code, ensuring the text comes back in the correct order, right-to-left for Arabic script.
The actor also provides boxes for each word, making the text searchable and usable in a prompt without needing additional fix-up steps.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to