OCR
Optical Character Recognition (OCR) allows users to extract text and tables from scanned documents with ease.
Key Highlights
-
Extract text from images within PDFs and scanned documents within PDFs effortlessly.
-
Support for multiple languages and fonts.
Getting started
The ocr parameter controls how OCR is applied:
"ocr": "false"(recommended) auto-detects, page by page, which pages need OCR and OCRs only those. It does not turn OCR off."ocr": "true"forces OCR on every page of the document.
Auto-detection ("ocr": "false") is the optimal setting for most documents, unless you know that the entire document is scanned.
There is no way to prevent OCR from running. With "ocr": "false", OCR may not run at all (for example, on a fully native PDF), but any page that auto-detection flags is still OCR'd.
If every page of your document is scanned and you want to force OCR on all of them, add "ocr": "true" to the data dictionary in requests.post:
response = requests.post(
api_url,
files=files,
data={
"document_type": "hierarchical_v2",
"ocr": "true"
}
)Automatic OCR detection
When "ocr": "false", Extract checks each page and decides whether it needs OCR, for example pages with no extractable text. Pages that need it are OCR'd; pages with native text are parsed directly. A single document can therefore mix OCR'd and natively parsed pages.
"ocr": "false" is not an opt-out, and it is the recommended setting: auto-detection already OCRs the pages that need it.
Because of this, enhanced_table_extraction="true" is safe to use on scanned documents. When auto-detection triggers OCR, tables on those pages are still extracted correctly.
Specifying a language
OCR detects the document's language automatically. If you already know the language, you can pass the optional language parameter to guide OCR and improve accuracy. This parameter only affects requests that actually go through OCR (whether via "ocr": "true" or automatic detection); it has no effect on natively parsed documents.
When language is omitted, the language is detected automatically.
response = requests.post(
api_url,
files=files,
data={
"document_type": "hierarchical_v2",
"ocr": "false",
"language": "spanish"
}
)language must be one of the following supported values:
arabic, chinese_simplified, chinese_traditional, english, french, german, hebrew, italian, japanese, korean, portuguese, russian, spanish, thai.
Important Notes
-
Please expect throughput and latency increases when using OCR.
-
Accuracy may vary depending on image quality and text complexity.
-
Feedback is encouraged to improve accuracy and expand language support.
Feedback and Support
We value your feedback to enhance OCR's performance. If you encounter any issues or have suggestions, please reach out to extract@kensho.com.
Stay Updated
Keep an eye on our release notes for updates and improvements to OCR based on your feedback and usage.