docling-project / docling-project/docling

PDF: figure caption words lose spaces producing CamelCase collapse

Open
#3,884 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
66.4k
Forks
4.8k
Avg merge
2d 21h
Merged PRs (30d)
84

Description

### Bug

Figure captions and headings where every word boundary space is lost, producing a single concatenated CamelCase string. This happens when the PDF producer stores the text as a single TJ text run with explicit kerning but no inter-word gaps.

Example from a real PDF:

```
Causeofdeathperlegaloutcomefornon-humancasesintheNetherlands
```

Should be:

```
Cause of death per legal outcome for non-human cases in the Netherlands
```

### Steps to reproduce

```python
from docling.document_converter import DocumentConverter

converter = DocumentConverter()
result = converter.convert("verkerk_forensic_necropsies_2026.pdf")
md = result.document.export_to_markdown()

# The figure caption has no spaces between words
assert "Causeofdeathperlegaloutcome" in md # Bug
```

### Expected behavior

The extractor should detect word boundaries even when the PDF stores the text as a single kerned run. Inter-word spaces should be preserved.

### Source location

`page_assemble_model.py:118 sanitize_text` / `backend/docling_parse_backend.py` - glyph-to-space conversion is missing for uniformly-spaced runs. The PDF producer wrote the heading as a single Tj/TJ text run with negative kerning but no inter-word Tm gap. The extractor reads ( ) TJ entries as kerning rather than as space tokens.

### Suggestion

Track glyph bboxes and inject a space when `next.x0 - cur.x1` exceeds approximately 0.2 times the average glyph width. Alternatively, detect runs where the inter-glyph spacing is uniform (no variation) and apply a word-boundary heuristic based on common English word patterns.

### Docling version

2.115.0

### Regression test PDF

- `verkerk_forensic_necropsies_2026.pdf` (4.4 MB) - figure caption with CamelCase collapse visible in the markdown output

Contributor guide

Open the contributing guide

Research direction

Start with sanitize_text at page_assemble_model.py:118 and then read backend/docling_parse_backend.py to trace glyph-to-space conversion for single TJ text runs. Run the provided DocumentConverter reproduction with verkerk_forensic_necropsies_2026.pdf and inspect the exported markdown. Done means the figure caption preserves spaces between words instead of producing the concatenated CamelCase string.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.