Tesseract OCR Command Line and Batch Script Generator
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.
Fill in
Use + to combine, for example eng+deu
Leave blank for none. Example: 0123456789.,-
Single file
tesseract "C:\scans\incoming\invoice_001.png" "C:\scans\ocr_out\invoice_001" -l eng --psm 3 --oem 1 --dpi 300 tsv
Single file with character whitelist (only if filled in)
tesseract "C:\scans\incoming\field_crop.png" "C:\scans\ocr_out\field_crop" -l eng --psm 3 --oem 1 -c tessedit_char_whitelist=[Character whitelist (optional)] tsv
Batch over a folder (PowerShell)
New-Item -ItemType Directory -Force -Path "C:\scans\ocr_out" | Out-Null
$files = Get-ChildItem -Path "C:\scans\incoming" -Include *.png,*.jpg,*.jpeg,*.tif,*.tiff -Recurse
foreach ($f in $files) {
$base = Join-Path "C:\scans\ocr_out" $f.BaseName
& tesseract $f.FullName $base -l eng --psm 3 --oem 1 --dpi 300 tsv
if ($LASTEXITCODE -ne 0) { Write-Warning ("OCR failed: " + $f.Name) }
}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.
Want this running against your scan inbox?
Optional: talk to an expert about a private OCR service for supplier invoices and certificates.
Optional. The tool and every export work without this. No spam.
How to use the generator
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
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.
- 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
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
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.
Frequently Asked Questions
Can Tesseract read PDF files directly?
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?
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?
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?
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.
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.
Related Tools
Tesseract Page Segmentation Modes and OEM Reference
Look up every Tesseract page segmentation mode (0 to 13) and OCR engine mode (0 to 3), with notes on which to use for invoices, stamps, labels and single fields.
Quality & InspectionOCR Confusable Characters Reference for AP Validation
A lookup of look-alike characters (0 and O, 1 and l, 5 and S and more) with the fields where they cause errors and a validation rule for each.
Developer ToolsInvoice Field Regex Generator (Python)
Set the labels your suppliers use and get a Python script with regexes for invoice number, PO number, invoice date and total amount, plus a total check.
Developer ToolsInvoice Extraction JSON Schema Generator
Create a JSON Schema that defines and validates the structure of extracted invoice data, including header fields, line items, confidence scores and review flags.
More Developer Tools tools
See all- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- SAP QM Inspection Lot ABAP SELECT Generator
- SAP Quality Notification Pareto SQL Query Generator
- SAP QM Usage Decision BAPI Skeleton
- ABAP Custom Exception Class Generator
- ABAP Unit Test Class Generator