Tesseract OCR
Runs Tesseract, the open-source
OCR engine, on a page image and writes what it reads to output_base plus the
format's extension: .txt, .pdf, .hocr, .tsv, or .xml for ALTO and
PAGE. The image carries Debian's build of Tesseract with the trained data for
every language and script Debian packages, so language can name any of them,
or several joined with +.
image is one image file, or a text file that lists image paths one per line:
Tesseract then reads them as the pages of one document, and the pdf format
gives one multi-page searchable PDF. Tesseract reads images, not PDFs; render a
PDF's pages to images first, or use swaleio/docling, which reads PDFs
directly.
Inputs
| Input | Required | Default | Description |
|---|---|---|---|
image |
yes | — | Absolute path of the image (PNG, JPEG, TIFF, ...), or of a text file listing one image path per line, read as pages of one document. |
output_base |
yes | — | Absolute path without an extension; Tesseract adds the format's. The directory must already exist. Point it at the mounted workspace (e.g. ${{env.WORKFLOW_STORAGE}}/scan) to share the result. |
language |
no | eng |
Tesseract language code, or several joined with +, such as eng+deu. tesseract --list-langs lists the 161 the image carries. |
psm |
no | 3 |
Page segmentation mode: 3, Tesseract's default, finds the layout itself; 6 reads one uniform block; tesseract --help-psm lists them all. |
format |
no | txt |
txt, pdf, hocr, tsv, alto or page. |
Outputs
None. The result is at output_base plus the format's extension, a path the
workflow chose; pass it to the next task.
Compute
CPU. Tesseract runs on the CPU; a page takes a second or two, so read many
pages as parallel tasks with for_each rather than on a larger compute type.
Example
Fetch two sample scans from Tesseract's test repository (Apache-2.0), list them as the pages of one document, and read them into one searchable PDF:
name: Tesseract example
compute_type: cpu-4
entry_point: main
blocks:
main:
tasks:
page_1:
name: Fetch page 1
uses: swaleio/http-request
args:
url: https://raw.githubusercontent.com/tesseract-ocr/test/232ff181c66516116ec0e84c4963f70de15050fd/testing/phototest.tif
expected_status: "200"
response_path: ${{env.WORKFLOW_STORAGE}}/scan/page-1.tif
page_2:
name: Fetch page 2
uses: swaleio/http-request
args:
url: https://raw.githubusercontent.com/tesseract-ocr/test/232ff181c66516116ec0e84c4963f70de15050fd/testing/eurotext.tif
expected_status: "200"
response_path: ${{env.WORKFLOW_STORAGE}}/scan/page-2.tif
list_pages:
name: List pages
uses: swaleio/bash
start_on:
- page_1
- page_2
args:
script: |
printf '%s\n' \
${{env.WORKFLOW_STORAGE}}/scan/page-1.tif \
${{env.WORKFLOW_STORAGE}}/scan/page-2.tif \
> ${{env.WORKFLOW_STORAGE}}/scan/pages.txt
ocr:
name: OCR
uses: swaleio/tesseract
start_on:
- list_pages
args:
image: ${{env.WORKFLOW_STORAGE}}/scan/pages.txt
output_base: ${{env.WORKFLOW_STORAGE}}/scan/document
format: pdf
Later tasks read the searchable PDF at
${{env.WORKFLOW_STORAGE}}/scan/document.pdf.
For the workflow syntax these examples use, see the workflow definition reference in the Swale documentation.
Licensed under the MIT License.