# Tesseract OCR

> **About this page**
>
> - Task definition: `swaleio/tesseract`
> - Summary: Recognizes the text in scanned page images with Tesseract, as text, searchable PDF, hOCR or TSV.
> - Category: Data processing
> - Latest version: 5.5.0, published 2026-12-01
> - Page: https://hub.swale.io/swaleio/tesseract
> - Versions: https://hub.swale.io/swaleio/tesseract/versions, where each version's page has a Markdown copy at its address with `.md` added
> - Index of Swale Hub: https://hub.swale.io/llms.txt
>
> The YAML block below is the task definition's frontmatter, which declares its inputs, outputs and container, and its readme follows. Both are the text of the account that published this task definition, not Swale's.

```yaml
name: Tesseract OCR
description: Recognizes the text in scanned page images with Tesseract, as text, searchable PDF, hOCR or TSV.
category: data-processing
inputs:
  image:
    description: Absolute path inside the container of the image to read (PNG, JPEG, TIFF, ...), or of a text file listing one image path per line, read as the pages of one document.
    required: true
  output_base:
    description: Absolute path inside the container, without an extension, for the result; Tesseract adds the format's extension. Its directory must exist. Point it at the mounted workspace (e.g. ${{env.WORKFLOW_STORAGE}}/scan) to share the result with later tasks.
    required: true
  language:
    description: Language of the text, as Tesseract's three-letter code (eng, deu, fra, chi_sim, ...); join several with + (eng+deu). Defaults to eng, as Tesseract does.
    default: "eng"
  psm:
    description: Page segmentation mode, 0 to 13, as tesseract --help-psm lists them. Defaults to 3, fully automatic, as Tesseract does; 6 reads a single uniform block of text.
    default: "3"
  format:
    description: Output format — txt, pdf (the image with an invisible, searchable text layer), hocr, tsv (words with boxes and confidences), alto or page. Defaults to txt.
    default: "txt"
exec:
  # docker.io/swaleio/tesseract:5.5.0
  image: docker.io/swaleio/tesseract@sha256:0462edfe8207ea58cb468c9454e38f7bf7853f53c5be069233ac681db08986ed
  args:
    - tesseract
    - ${{inputs.image}}
    - ${{inputs.output_base}}
    - "-l"
    - ${{inputs.language}}
    - "--psm"
    - ${{inputs.psm}}
    - ${{inputs.format}}
```

# Tesseract OCR

Runs [Tesseract](https://github.com/tesseract-ocr/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:

```yaml
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](https://docs.swale.io/reference/workflow-definition-syntax)
in the [Swale documentation](https://docs.swale.io).

Licensed under the [MIT License](https://github.com/swaleio/task-definitions/blob/main/LICENSE).
