# Tesseract OCR Command Line and Batch Script Generator

> Source: https://netray.co/tools/tesseract-ocr-command-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Build the exact tesseract command for a single file and a PowerShell loop for a whole folder, with language, page segmentation mode, resolution and output format set from a form.

## Category

developer

## Audience

- ERP developer
- AP automation engineer
- IT administrator

## Tool

**Kind:** template

**Output:** code

**Language:** powershell

**Fields:**

#### Input folder

**Key:** input_dir

**Type:** text

**Default:** C:\scans\incoming

#### Output folder

**Key:** output_dir

**Type:** text

**Default:** C:\scans\ocr_out

#### Language code(s)

**Key:** lang

**Type:** text

**Default:** eng

**Help:** Use + to combine, for example eng+deu

#### Page segmentation mode

**Key:** psm

**Type:** select

**Options:**

- 3
- 4
- 6
- 7
- 11
- 12

**Default:** 3

#### OCR engine mode

**Key:** oem

**Type:** select

**Options:**

- 1
- 3

**Default:** 1

#### Image resolution (dpi)

**Key:** dpi

**Type:** number

**Default:** 300

#### Output format

**Key:** fmt

**Type:** select

**Options:**

- txt
- tsv
- pdf
- hocr

**Default:** tsv

#### Character whitelist (optional)

**Key:** whitelist

**Type:** text

**Help:** Leave blank for none. Example: 0123456789.,-

**Blocks:**

#### Single file

**Body:** tesseract "{{input_dir}}\invoice_001.png" "{{output_dir}}\invoice_001" -l {{lang}} --psm {{psm}} --oem {{oem}} --dpi {{dpi}} {{fmt}}

#### Single file with character whitelist (only if filled in)

**Body:** tesseract "{{input_dir}}\field_crop.png" "{{output_dir}}\field_crop" -l {{lang}} --psm {{psm}} --oem {{oem}} -c tessedit_char_whitelist={{whitelist}} {{fmt}}

#### Batch over a folder (PowerShell)

**Body:** New-Item -ItemType Directory -Force -Path "{{output_dir}}" | Out-Null
$files = Get-ChildItem -Path "{{input_dir}}" -Include *.png,*.jpg,*.jpeg,*.tif,*.tiff -Recurse
foreach ($f in $files) {
    $base = Join-Path "{{output_dir}}" $f.BaseName
    & tesseract $f.FullName $base -l {{lang}} --psm {{psm}} --oem {{oem}} --dpi {{dpi}} {{fmt}}
    if ($LASTEXITCODE -ne 0) { Write-Warning ("OCR failed: " + $f.Name) }
}

**Notes:** Confirm that tesseract is on the PATH and that the traineddata file for each language is in the tessdata folder. Tesseract reads images, not PDFs, so convert PDF pages to PNG or TIFF first (for example with pdftoppm). The pdf format produces a searchable PDF. A character whitelist helps on numeric crops but can reduce accuracy on mixed text.

## Content

**Intro:** Fill in the form and copy a working tesseract command for one file, a whitelisted field crop, and a PowerShell loop for a folder of scans. It saves you from remembering the flag order and quoting rules on Windows.

**Sections:**

#### How to use the generator

**Body:** Set the input and output folders, language codes, page segmentation mode and output format. The commands update as you type. Use tsv when you plan to extract fields by coordinate and confidence, txt for quick tests, pdf to create searchable archives of supplier documents, and hocr when another tool needs the layout. Copy the snippet into a script file and run it from a service account that has read access to the scan folder.

#### What each flag does

**Body:** The -l flag selects the trained language data. The --psm flag controls how the page is divided into text blocks, and --oem selects the engine, where 1 is the LSTM neural net. The --dpi flag tells Tesseract the resolution when the image has no metadata. The final argument is a config name such as tsv or pdf that selects the output renderer.

**Bullets:**

- Use eng+deu style values for multi language documents
- Whitelists apply through -c tessedit_char_whitelist
- Output files get the extension added automatically
- Exit code is non zero on failure, which the loop reports

#### Preparing images

**Body:** OCR quality is decided before Tesseract runs. Scan at 300 dpi in grayscale, deskew pages, remove dark borders and avoid lossy JPEG compression on small text. For photos of delivery notes taken with phones, correct perspective and brightness first. Re-running the same file with two different psm values and comparing confidence is a cheap way to tune a document type.

#### Common mistakes

**Body:** Passing the output name with an extension creates files like invoice.tsv.tsv. Forgetting the quotes breaks paths with spaces. Feeding multi page PDFs directly fails on builds without PDF support. Whitelisting digits on a full page makes the engine force letters into digits, so use it only on cropped numeric fields.

**Cta:** If you want scanned supplier documents to flow into your ERP with validation and human review, Netray can design a private, on-prem pipeline around this kind of OCR step.

**Faq:**

#### Can Tesseract read PDF files directly?

**Answer:** Not reliably. Tesseract is designed for image input, and PDF reading depends on how it was built. The common approach is to convert each PDF page to a 300 dpi PNG or TIFF with a tool such as pdftoppm, then run OCR on the images.

#### What output format should I use for invoice extraction?

**Answer:** Use tsv. It returns every word with its bounding box, page, line and a confidence value, which lets your code rebuild lines, locate labels and flag low confidence words. Plain txt loses coordinates and the confidence needed for review rules.

#### How do I OCR several languages at once?

**Answer:** Join language codes with a plus sign, for example eng+deu, and make sure each traineddata file is installed. Accuracy can drop when too many languages are combined, so use only the languages that actually appear on your supplier documents.

#### Why does the batch script write nothing?

**Answer:** Usual causes are an input folder with no matching extensions, a missing tesseract on the PATH for the account running the script, or missing language data. The loop prints a warning for a non zero exit code, so check the console output first.

## Search terms

tesseract command line example, tesseract batch ocr folder powershell, tesseract tsv output command, tesseract searchable pdf command, tesseract whitelist digits, tesseract ocr invoices command, tesseract dpi option

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
