scanlayer
Docs / Reference

CLI Reference

Every flag scanlayer accepts, and what each exit code means. For task-oriented walkthroughs, see Examples.

Usage

bash
scanlayer INPUT [INPUT ...] [-o OUTPUT] [options]
bash
# Language and DPI
scanlayer invoice.jpg -o invoice.pdf --lang fra --dpi 300

# Verbose logging
scanlayer invoice.jpg -o invoice.pdf --verbose

# PDF metadata + JPEG quality
scanlayer invoice.jpg -o invoice.pdf --jpeg-quality 90 --title "Invoice 2024"

# Batch conversion: multiple inputs, output must be a folder
scanlayer *.jpg -o ./converted/

# Export raw OCR result instead of a PDF
scanlayer invoice.jpg -o invoice.json --format json

# Debug overlay alongside any format
scanlayer invoice.jpg -o invoice.pdf --debug-image

# No -o: writes invoice.pdf and invoice_debug.png next to the input
scanlayer invoice.jpg --debug-image

# Validate a batch (files exist, Tesseract reachable, output writable)
# without running OCR or writing anything
scanlayer *.jpg -o ./converted/ --dry-run

All options

OptionDescription
inputOne or more source paths: images (jpg, png, tiff, bmp, gif, webp, jp2) or native .pdf. Glob patterns are expanded. Multiple inputs + a folder -o means batch mode.
-o, --outputOptional. Output path (single input), or a folder (batch mode). If omitted, each output is written next to its own input, same stem, extension from --format, which also lets --debug-image be used on its own without naming an output file. Must be a file path, not a folder, when --merge is used, and is required in that case: a merge combines multiple inputs into one file, so there is no single input to derive a name from.
--formatpdf (default), txt, json, tsv, or hocr. See Output Formats.
--debug-imageAlso save <output-stem>_debug.png, whatever --format is. See Debug Visualization.
--langTesseract language(s), e.g. fra, eng, fra+eng. Default: fra+eng.
--dpiDPI to use only if it can't be detected from the image itself.
--jpeg-qualityJPEG quality for the PDF background image (default 82), used when the background isn't encoded as PNG.
--whitelistCharacters Tesseract is allowed to recognize, e.g. digits only for a numeric field.
--blacklistCharacters Tesseract should ignore.
--min-confidenceInteger 0–100. Words below this confidence are dropped. Default 35.
--psmForce a single Tesseract page segmentation mode (0–13, excluding 0 and 2, which are rejected: they only run orientation/script detection and produce no OCR text). Skips the normal multi-PSM race entirely.
--orientationOmit for automatic (EXIF + OSD + deskew). none disables all correction. A number is an exact clockwise angle in degrees, skipping auto-detection. See examples.
--title, --author, --subjectPDF metadata fields.
--fontPath to a TTF font to embed in the invisible text layer, overriding automatic selection. Useful for scripts the built-in selection doesn't cover (Arabic, Hebrew, Thai, Devanagari…).
--configPath to a .yaml/.yml/.json profile applied via configure() before any other flag is processed (later CLI flags still override it). See Configuration.
--no-column-detectionDisable multi-column reading-order reconstruction for this run only.
--mergeCombine all inputs into one multi-page output PDF instead of one file per input. Only supported with --format pdf. See Multi-Page and Merge.
--dry-runCheck that every input file exists and is readable, that Tesseract is reachable, and that output paths are writable, then exit, without running OCR or writing any output. Same exit codes as a normal run. With --merge, validation fails fast on the first bad page (matching convert_merge(), which produces one combined output and never returns exit code 5).
-v, --verboseDEBUG-level logging.
-q, --quietOnly log errors. Mutually exclusive with --verbose.
--forceBuild output even if the source looks blank/near-uniform (background-only PDF, or an empty result for other formats), instead of raising an error.

Exit codes

The CLI's exit code is a flattened view of the library's exception hierarchy: see Library API → Exceptions for the exact classes each one corresponds to.

CodeMeaningTypical cause
0Successn/a
1User errorFile not found, invalid --format, blank page without --force
2Environment errorTesseract missing/misconfigured, poppler missing for PDF input
3Unexpected errorA bug: rerun with --verbose for the full traceback
4Processing errorOCR or PDF stage failed operationally (e.g. a timeout), after every precondition already passed
5Partial batch failureMultiple inputs given, at least one failed, the rest still ran
Debugging exit code 3 An unexpected error (a bug, not a documented failure mode) always prints the exception type and message; add --verbose to also get the full Python traceback in the log output.

Running from a checkout

If you installed with Option B in Installation (no pip install scanlayer), there is no scanlayer command on PATH. Every example on this page and in Examples still works, just substitute python -m scanlayer for scanlayer:

bash
python -m scanlayer invoice.jpg -o invoice.pdf --lang fra --dpi 300