OCR Extract Table
OCR Extract Table
Section titled “OCR Extract Table”Type: ocr-extract-table · Package: OCR Activities v1.2.5 · Output: DataTable
Since: v1.2.0
Detects a table inside an image, grouping the recognized words into rows and columns by position, and returns it as a DataTable. Useful to extract a tabular listing from a scanned document (an invoice detail, a data table).
How it works
Section titled “How it works”Runs OCR on the image (with preprocess = "auto" by default) and rebuilds the table from the coordinates of each word:
- Rows: each recognized line is a row.
- Columns: it looks for the horizontal positions where words repeatedly start across the document (grouping starts less than 25 px apart) and uses them as columns. A position counts as a column if at least 2 words start there (or as many as a quarter of the number of lines, in long documents).
- Each word goes to the column that starts just before it; several words in the same cell are joined with a space.
- It discards rows with fewer filled cells than
minColumns(titles, footers, loose text). - With
hasHeader = true, the first remaining row gives the column names.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | — | Path to the image file (.png, .jpg, .bmp, .tiff). |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
language | string | "eng" | Text language: Tesseract code (eng, spa, eng+spa) or regional tag (es-CO). See language. |
preprocess | string | "auto" | Prior cleanup: none · auto · deskew · binarize. See preprocessing. |
hasHeader | bool | true | Treat the first detected row as column names. |
minColumns | int | 2 | Discard rows with fewer filled cells than this number. Values below 1 are treated as 1. |
Output
Section titled “Output”Returns a DataTable with every cell as text:
- Columns: with
hasHeader = true, the texts of the first row; an empty header is namedColNand a repeated one gets a suffix (Amount,Amount_2). WithhasHeader = false,Col1,Col2… - Rows: the other detected rows; cells with no word stay empty.
- No text or no valid rows: an empty DataTable (no columns or rows). Check it with
rowCount(table) == 0.
Example
Section titled “Example”OCR Extract Table path = scanPath language = "eng" minColumns = 3 → output: tableIf condition = rowCount(table) == 0 └─ then: Throw message = "No table was detected in the image"For Each items = table itemVariable = row └─ activities: Log message = str(row["Description"]) + " — " + str(row["Amount"])Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
File not found. | The path does not exist on the robot’s machine. |
'path' is required. | path is missing. |
Tesseract language '…' not found at '…'. Available: [eng, spa]. | The language code is not installed. |
Could not read the image. | The file is not a valid image or is damaged (preprocessing is on by default). |
| Error reading a missing column in a later step | Column names come from OCR and may vary (accents, case). Check table.Columns or use hasHeader = false and access Col1, Col2. |
Related activities
Section titled “Related activities”- OCR Get Lines — the raw lines and coordinates, for fine control.
- DataTable — filter, sort and summarize the extracted table.
- PDF Get Text — for documents with real text.