OCR Engine Configuration#
Docling's OCR subsystem is configured through two orthogonal mechanisms: ocr_options on PdfPipelineOptions selects and tunes the engine per-conversion, and DebugSettings (in settings.py) enables global debug visualization of OCR and adjacent pipeline stages.
Enabling OCR#
OCR is activated via PdfPipelineOptions:
from docling.datamodel.pipeline_options import PdfPipelineOptions, EasyOcrOptions
opts = PdfPipelineOptions()
opts.do_ocr = True # default: True
opts.ocr_options = EasyOcrOptions(lang=["en", "de"])
do_ocr=True (default) applies OCR to bitmap regions. Set force_full_page_ocr=True on any OcrOptions subclass to always OCR the entire page . bitmap_area_threshold (default 0.05) skips OCR on bitmaps smaller than 5% of the page area .
Available Engines#
All engine options inherit from OcrOptions and are set as PdfPipelineOptions.ocr_options. The default is OcrAutoOptions().
| Class | kind | Notes |
|---|---|---|
OcrAutoOptions | "auto" | Probes runtime and picks best available engine (see below) |
EasyOcrOptions | "easyocr" | 80+ languages via deep learning; GPU-accelerated |
TesseractCliOcrOptions | "tesseract" | CLI-based; requires system Tesseract installation |
TesseractOcrOptions | "tesserocr" | Python bindings (tesserocr); same data files as CLI |
OcrMacOptions | "ocrmac" | macOS Vision framework; Apple Silicon native |
RapidOcrOptions | "rapidocr" | Lightweight; multiple inference backends (ONNX, OpenVINO, Paddle, Torch) |
NemotronOcrOptions | "nemotron-ocr" | NVIDIA Nemotron OCR; uses pipeline-level artifacts_path |
KserveV2OcrOptions | "kserve_v2_ocr" | Remote KServe v2 server (Triton); gRPC or HTTP |
The deprecated OcrEngine enum is no longer the canonical list — use get_ocr_factory().registered_kind to enumerate all registered engines at runtime (including external plugins).
Auto-Selection Logic#
OcrAutoOptions triggers OcrAutoModel, which probes the environment in this order:
- macOS →
OcrMacModel - Linux →
NemotronOcrModel - Fallback chain: RapidOCR (onnxruntime) → EasyOCR → RapidOCR (torch)
Because lang defaults to [] with OcrAutoOptions , language selection is deferred to the engine that gets chosen. Specify an explicit engine class to control languages.
Engine-Specific Options Reference#
EasyOcrOptions — key fields :
lang: ISO 639-1 codes, default["fr", "de", "es", "en"]use_gpu:None(auto-detect),True, orFalseconfidence_threshold:0.5— filters low-confidence resultsmodel_storage_directory: override model cache pathrecog_network:"standard"or"craft"
TesseractCliOcrOptions / TesseractOcrOptions — key fields :
lang: ISO 639-2 codes, default["fra", "deu", "spa", "eng"]psm: Tesseract Page Segmentation Mode (0–13);None= Tesseract defaultpath: overrideTESSDATA_PREFIX; CLI also exposestesseract_cmd
RapidOcrOptions — key fields :
backend:"onnxruntime"(default),"openvino","paddle","torch"text_score: detection confidence threshold (default0.5)use_det,use_cls,use_rec: individually toggle detection/classification/recognition stagesprint_verbose: enable verbose logging from the RapidOCR enginerapidocr_params: dict pass-through for any other RapidOCR setting- ⚠️ Known issue: read-only filesystems (e.g., Databricks) may cause failures; prefer Tesseract there
OcrMacOptions — key fields :
lang: locale codes, default["fr-FR", "de-DE", "es-ES", "en-US"]recognition:"accurate"(default) or"fast"framework:"vision"(Apple Vision framework)
NemotronOcrOptions — key fields :
lang:"english"or"multilingual"(Nemotron OCR v2)merge_level:"word","sentence"(default), or"paragraph"— granularity of output cellsbatch_size: number of image crops to process together (default8)
KserveV2OcrOptions — key fields :
url:host:portfor gRPC,http(s)://host:portfor HTTPtransport:"grpc"(default) or"http"model_name: registered model name on the server (default"ocr")scale: image scale multiplier (default2.0)- See the KServe v2 notes in the knowledge base for authentication, TLS, and load-balancing details.
Debug Visualization#
DebugSettings in settings.py controls global debug image output. All flags default to False; images are written to debug_output_path (default: ./debug/).
| Flag | What is saved |
|---|---|
visualize_ocr | OCR bounding boxes and detected cells per page |
visualize_cells | PDF text cell boxes from page preprocessing |
visualize_layout | Post-processed layout clusters (annotated with label + confidence) |
visualize_raw_layout | Raw layout model output before post-processing |
visualize_tables | Table structure predictions per detected table |
profile_pipeline_timings | Timing data for each pipeline stage |
Configure via environment variables (prefix DOCLING_, nested delimiter _) or programmatically:
from docling.datamodel.settings import settings, DebugSettings
settings.debug = DebugSettings(
visualize_ocr=True,
visualize_layout=True,
debug_output_path="/tmp/docling_debug",
)
Use the scoped() context manager to temporarily override settings and guarantee restoration:
from docling.datamodel.settings import scoped, DebugSettings
with scoped(debug=DebugSettings(visualize_layout=True)):
result = converter.convert(source)
Key Source Files#
| File | Purpose |
|---|---|
docling/datamodel/pipeline_options.py | All OcrOptions subclasses and PdfPipelineOptions.ocr_options |
docling/datamodel/settings.py | DebugSettings, AppSettings, scoped() |
docling/models/stages/ocr/auto_ocr_model.py | OcrAutoModel — runtime engine selection logic |
docling/models/base_ocr_model.py | Base OCR model; writes visualize_ocr output |
docling/models/stages/layout/layout_model.py | Writes visualize_layout / visualize_raw_layout output |
docling/models/stages/table_structure/ | Writes visualize_tables output (V1 + V2) |
docling/models/stages/page_preprocessing/page_preprocessing_model.py | Writes visualize_cells output |
docling/models/factories/__init__.py | get_ocr_factory() — plugin-based engine registry |