Expose the OCR detector's input-size limit, so large-format pages aren't silently downscaled
Requested feature
We ingest construction drawings. The pixels are present in the files — several sheets embed a 21200 × 14800 px raster, 400 DPI on a 1346 × 940 mm sheet — and their title blocks are plainly legible when cropped at native resolution. Through docling they come back as a few hundred garbled characters.
images_scale is not the knob, although it looks like it is: it only sizes the page/picture images
docling exports, so raising it costs render time and changes OCR not at all. (That cost us a round
of investigation, so it may be worth a note in the docs regardless of this request.)
Docling hands the OCR engine one image per page, and every engine caps how large an image its text
detector will look at. That cap is not reachable through PdfPipelineOptions, and the result on a
large-format page is silent: no error, no warning, just text that comes back as noise.
For RapidOCR the binding limit is Global.max_side_len = 2000 (rapidocr/config.yaml, applied in
rapidocr/main.py). Docling passes no override, so the whole page image is scaled down to a
2000 px longest side before detection. OcrOptions.scale = 3.0 renders the page at 216 DPI first,
and most of that is then discarded.
Effective OCR resolution is therefore 2000 px / the page's physical long side:
| Sheet | Effective DPI | 2.5 mm lettering is |
|---|---|---|
| 210 × 297 mm (A4) | 171 DPI | 17 px |
| 420 × 594 mm (A2) | 86 DPI | 8 px |
| 841 × 1189 mm (A0) | 43 DPI | 4 px |
| 1346 × 940 mm | 38 DPI | 4 px |
Note the first row: even A4 is downscaled from the 216 DPI docling just rendered.
EasyOCR has the same shape of limit with a different number — canvas_size = 2560 in
easyocr/imgproc.py: resize_aspect_ratio, which EasyOcrModel does not pass either.
Proposed solution
Expose the detector input size on OcrOptions, e.g.:
class OcrOptions(BaseOptions):
...
detector_max_side_px: int | None = None # None = engine default
passed through to Global.max_side_len for RapidOCR and canvas_size for EasyOCR. Even just
plumbing the existing engine parameters through would let callers with high-resolution sources opt
into using them.
A smaller, cheaper alternative that would also help: log a warning when the page image handed to the detector is about to be downscaled, and by how much. Right now the quality loss is completely invisible from the outside.
Alternatives
We now pre-tile such a page ourselves: cut it into overlapping pieces that each render inside the
detector's cap, submit them as a multi-page PDF, and let docling reassemble the text. Measured
against the sheets' own embedded text layers (six large-format drawings, force_ocr on, scored
token-wise), mean recall goes from 24.2% to 84.6%, with precision rising from 13–49% to ~90%.
That is a lot of machinery outside docling to work around one unreachable constant, and the costs are all downstream of having to rasterise:
- It can only be applied to a page carrying no text layer of its own, because rendering destroys that text — and the decision is therefore per page, not per document. A mixed document (a scanned drawing set with one born-digital sheet) has to be reassembled page by page, copying some pages verbatim and rasterising others.
- The tiles overlap slightly so a word on a seam survives whole, which means text inside the overlap band is read twice and appears twice in the reconstructed document.
- Rasterising a large sheet is not cheap: ~15 s and several hundred MB of peak RSS per sheet, dominated by decoding the page's own embedded image.
None of that would be necessary if the detector could simply be told to look at a larger image.
Related
#3499 proposes a layout-first surgical OCR mode for very high-resolution archival scans. It overlaps in motivation, but this is a narrower ask — one option that already exists inside both engines, just not reachable from docling — and it applies to ordinary A0/A1 drawings well short of 72 MP.
Environment
docling-serve1.31.0 (quay.io/docling-project/docling-serve-cpu:v1.31.0), docling-slim 2.121.0- OCR engine: RapidOCR via the
autopreset, PP-OCRv6 - Numbers above were read from the running container, not inferred.
Note that I drafted this request with the help from AI.
The silent-downscale point stands, and the numbers check out — rapidocr/config.yaml really does ship Global.max_side_len: 2000 and easyocr 1.7.2's readtext really does default canvas_size=2560. One correction though: the cap is already reachable for RapidOCR, just not for EasyOCR, and that splits this into two quite different asks.
RapidOcrOptions has a rapidocr_params pass-through, and RapidOcrModel merges it into the dict it hands to RapidOCR(params=...) right before construction. RapidOCR applies that through ParseParams.update_batch, so the detector cap moves today:
RapidOcrOptions(rapidocr_params={"Global.max_side_len": 4000})
Checked against the engine rather than the docs, going through docling's own option object:
RapidOcrOptions() -> Global.max_side_len = 2000
RapidOcrOptions(rapidocr_params={"Global.max_side_len": 4000}) -> Global.max_side_len = 4000
So for your construction drawings there is a workaround available right now, which may be worth trying before any of this lands.
EasyOCR is the real gap. EasyOcrOptions has no equivalent pass-through, it sets extra="forbid", and EasyOcrModel calls self.reader.readtext(im) with no keyword arguments at all — so canvas_size and mag_ratio keep their defaults and nothing a caller can write will change that. EasyOcrOptions(canvas_size=6000) raises ValidationError.
That leaves three separable pieces, and I would rather you pick than have me guess:
- An EasyOCR pass-through, mirroring
rapidocr_params— smallest change, consistent with what RapidOCR already offers, no new cross-engine concept. It would need to reachreadtext()rather thanReader(), since that is wherecanvas_sizelives. - The
detector_max_side_pxoption you proposed, normalising the concept across engines. Nicer for callers, but it is a new public field onOcrOptionsand it has to mean something sensible for the engines that have no such cap — tesseract, ocrmac, and the remote ones. - The downscale warning. Independent of both, and the part I would want regardless: right now the quality loss is invisible, which is what cost you the investigation. Logging the page image size, the detector cap and the resulting effective DPI when a downscale is about to happen would have answered your question in one run.
I am happy to implement whichever of these you want. My instinct is 3 first since it is additive and uncontroversial, then 1, and to leave 2 until there is a reason to normalise. But it is your API, so say which and I will follow.
One aside on the docs point you raised: images_scale versus OcrOptions.scale tripped you up, and the RapidOCR workaround above is not documented anywhere I can find either. Worth a short note in the OCR docs whichever way this goes.
I'm not sure whether you're actually asking for my opinion here, since a part of the considerations seem more docling-internal. But, for what it's worth:
- I agree that doing 3. first makes a lot of sense.
- As a user, I could live with having only 1 and 3, and I leave it up to the docling team to decide about consistency.
- Thanks for letting me know the work around that already exists for RapipOCR. I think it deserves to be documented in a way that it's easier to find. (For sure implementing 3. will be part of making it easier to find.)
A follow up, after running some experiments. One thing worth adding for anyone arriving here from docling-serve rather than the library, and then some numbers, since I had a ground-truth corpus to hand.
Note about the work around availability
Through docling-serve the workaround is gated. ocr_custom_config is advertised in docling-serve 1.31.0's OpenAPI, but a conversion carrying it fails at run time by default:
ERROR docling_jobkit.orchestrators.local.worker - Worker 1 failed to process job …:
Custom OCR configuration is not allowed. Please use a preset or contact your administrator.
The setting is DoclingServeSettings.allow_custom_ocr_config, default false, so the server has to be started with DOCLING_SERVE_ALLOW_CUSTOM_OCR_CONFIG=true. With that set, {"kind": "rapidocr", "rapidocr_params": {"Global.max_side_len": 4000}} works exactly as you describe. So "a workaround is available right now" holds for library users and is conditional for docling-serve users — worth a line in the docs note you suggested, since it is the deployment shape where nothing in the API response says why the conversion failed.
Measurements
Measured on the drawings from the report. Six large-format sheets whose own text layer is the ground truth, force_ocr so the text layer is discarded and the pixels are read, scored token-wise against it. One fresh docling-serve-cpu:v1.31.0 container per arm, --memory=8g.
| Arm | Mean recall | Mean precision | Wall time | Tiles |
|---|---|---|---|---|
| untiled, cap 2000 (default) | 25.3% | 43.3% | 78 s | — |
| untiled, cap 4000 | 73.0% | 83.3% | 116 s | — |
| untiled, cap 8000 | OOM-killed at 8 GiB after 3 of 6 | — | ||
| external tiling, tiles cut for 2000 | 90.7% | 89.5% | 291 s | 44 |
| external tiling, tiles cut for 4000 | 92.3% | 93.4% | 139 s | 14 |
This shows that raising the cap to 4000 without tiling does improve the results quite a bit, but still doesn't beat our tiling solution. We could gain a slightly better result and a performance boost by combining the increased cap with tiling. If we'd want to get rid of the tiling, we need a bigger machine. What we implement is still to be decided.
I think this confirms my previous reply that 3 is the most important and urgent fix. But since we're also investigating whether we can get better results with EasyOCR, it would be great if we were able to increase the cap there too.
Classification labels added: priority:medium, pdf.
These labels are advisory. Maintainers can correct them. The workflow preserves these corrections.