docling-project / docling-project/docling

Inconsistent text extraction (table headlines outside tables) - missing text headlines in markdown/JSON output

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

Description

### Bug

Docling fails to reliably extract table captions/headlines from PDF documents. Specifically, when processing `check.pdf` which contains two table captions ("Tabelle 6" and "Tabelle 7"), docling's output is inconsistent:

- **Markdown output**: Contains "Tabelle 7" (below the table) but missing "Tabelle 6"
- **JSON output**: Contains "Tabelle 7" but missing "Tabelle 6"

This unreliable text extraction is problematic for RAG systems that depend on accurate document processing and context preservation.

**Expected behavior**: Both table captions (headlines) should be consistently extracted in both markdown and JSON outputs.

**Actual behavior**: Inconsistent extraction - some table captions are missing entirely.

### Steps to reproduce

1. **Prepare test PDF**: Use `check.pdf` containing two table captions:
- Page 1, Line 287: "Tabelle 6: Endenergieverbrauch erneuerbarer Energien im Verkehrssektor"
- Page 2, Line 305: "Tabelle 7: Entwicklung des Energieverbrauchs insgesamt in Deutschland"

2. **Verify expected content with PyMuPDF** (baseline test):

Create and run this test script to verify the PDF contains the expected table captions:

```python
#!/usr/bin/env python3
"""
Slim PyMuPDF test for docling bug report.
This test demonstrates text extraction from PDF using PyMuPDF (fitz).
"""

import re
import fitz # PyMuPDF

def test_pymupdf_text_extraction(pdf_path="check.pdf"):
"""Test PyMuPDF text extraction and search for 'Tabelle' pattern."""
print("Testing PyMuPDF text extraction...")

doc = fitz.open(pdf_path)
matches = []

for page_num in range(len(doc)):
page = doc[page_num]
text = page.get_text()

for line_num, line in enumerate(text.splitlines(), 1):
if re.search(r'\bTabelle\b', line, re.I):
matches.append(f"Page {page_num + 1}, Line {line_num}: {line.strip()}")

doc.close()

if matches:
print(f"Found {len(matches)} 'Tabelle' matches:")
for match in matches:
print(f" {match}")
else:
print("No 'Tabelle' matches found")

return matches

if __name__ == "__main__":
# Run the test
matches = test_pymupdf_text_extraction()
print(f"\nResult: {'SUCCESS' if matches else 'NO MATCHES'} - Found {len(matches)} matches")
```

Expected output:
```
Testing PyMuPDF text extraction...
Found 2 'Tabelle' matches:
Page 1, Line 287: Tabelle 6: Endenergieverbrauch erneuerbarer Energien im Verkehrssektor
Page 2, Line 305: Tabelle 7: Entwicklung des Energieverbrauchs insgesamt in Deutschland
Result: SUCCESS - Found 2 matches
```

3. **Process with docling**:
```python
from docling.document_converter import DocumentConverter

converter = DocumentConverter()
result = converter.convert("check.pdf")

# Check markdown output
md_content = result.document.export_to_markdown()
print("Tabelle 6 in markdown:", "Tabelle 6" in md_content)
print("Tabelle 7 in markdown:", "Tabelle 7" in md_content)

# Check JSON output
json_content = result.document.export_to_dict()
json_str = str(json_content)
print("Tabelle 6 in JSON:", "Tabelle 6" in json_str)
print("Tabelle 7 in JSON:", "Tabelle 7" in json_str)
```

4. **Observe inconsistent results**:
- Markdown: Both "Tabelle 6" and "Tabelle 7" missing (see `exported_document_single_pages.md`)
- JSON: "Tabelle 7" present, "Tabelle 6" missing (see `exported_document_single_pages.json`)

5. **Verify the issue with provided output files**:
- Search for "Tabelle" in `exported_document_single_pages.md` - no matches found
- Search for "Tabelle" in `exported_document_single_pages.json` - only "Tabelle 7" found, "Tabelle 6" missing

### Docling version

```
Name: docling
Version: 2.50.0
```

### Python version

```
Python 3.12.11
```

### Additional Information

**Test files provided**:
- `check.pdf` - Test document containing the problematic table captions
- `exported_document_single_pages.md` - Docling markdown output showing missing table captions
- `exported_document_single_pages.json` - Docling JSON output showing partial table caption extraction
- PyMuPDF test code (included above) - Demonstrates reliable text extraction baseline

**Impact**: This bug significantly affects RAG systems and document processing pipelines that rely on accurate text extraction for context-dependent operations.

**Workaround**: -

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.