Skip to content

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).

Runs OCR on the image (with preprocess = "auto" by default) and rebuilds the table from the coordinates of each word:

  1. Rows: each recognized line is a row.
  2. 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).
  3. Each word goes to the column that starts just before it; several words in the same cell are joined with a space.
  4. It discards rows with fewer filled cells than minColumns (titles, footers, loose text).
  5. With hasHeader = true, the first remaining row gives the column names.
ParameterTypeDefaultDescription
pathstring—Path to the image file (.png, .jpg, .bmp, .tiff).
ParameterTypeDefaultDescription
languagestring"eng"Text language: Tesseract code (eng, spa, eng+spa) or regional tag (es-CO). See language.
preprocessstring"auto"Prior cleanup: none · auto · deskew · binarize. See preprocessing.
hasHeaderbooltrueTreat the first detected row as column names.
minColumnsint2Discard rows with fewer filled cells than this number. Values below 1 are treated as 1.

Returns a DataTable with every cell as text:

  • Columns: with hasHeader = true, the texts of the first row; an empty header is named ColN and a repeated one gets a suffix (Amount, Amount_2). With hasHeader = 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.
OCR Extract Table path = scanPath language = "eng" minColumns = 3 → output: table
If 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"])
MessageCause 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 stepColumn names come from OCR and may vary (accents, case). Check table.Columns or use hasHeader = false and access Col1, Col2.
  • 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.