Since 7.26.0, duplicate removal deletes letters from real text ("Specifies" → "pecifies", "ENFORCED" → "NFORCED")
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 42/100
Línea de trabajo
Run the reproduction script with DecodeConfig() and do_remove_duplicate_cells=False first to confirm the missing letters. Then read remove_duplicate_cells in src/parse/page_item_sanitators/cells.h (exact-match pass around lines 1574-1591), its call from decode_page in src/parse/pdf_decoders/page.h, and the tolerant and remove_overlapping_text_cells passes below it. Use tests/test_unit_overprinted_text.py and Docling's redp5110_sampled.pdf page 10 as checks; done means both synthetic cases and the p10 lines decode whole while the true duplicate ENABLE is still removed. The issue reports no clean fix yet, so the first task is to understand why exact glyph matching is too broad.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
Since 7.26.0, the default DecodeConfig() deletes single letters from real text when the page draws the same text twice. A word can lose its first letter or letters in the middle.
On Docling's own test fixture redp5110_sampled.pdf, page 10:
- Expected:
Specifies that the row permission is to be initially disabled - Observed:
pecifies that the row permission is to be initially sabled - Expected (second copy of a bold heading):
ENFORCED FOR ALL ACCESS - Observed:
NFORCED FOR ALL ACCESS
7.25.0 reads both lines correctly. 7.26.0, 7.27.0 and 7.27.1 drop the letters. DecodeConfig(do_remove_duplicate_cells=False) restores them.
This is real content loss, not a copy being kept. The letters are missing from char_cells, word_cells and textline_cells. It has also reached Docling's reference data: on Docling main, tests/data/pdf/groundtruth/redp5110_sampled.json now expects pecifies that the row permission is to be initially sabled and NFORCED FOR ALL ACCESS. That file was regenerated in docling-project/docling#5456 (commit 4c0a96de53). The version before it expected Specifies … disabled and ENFORCED FOR ALL ACCESS.
Reproduction
The script writes a one-page PDF itself (no PDF library needed). It prints the text lines docling-parse decodes, with duplicate removal on and off.
"""Duplicate removal deletes letters from real text since docling-parse 7.26.0.
Writes a one-page PDF (no third-party PDF library) and prints the text lines
docling-parse decodes, with duplicate removal on (the default) and off.
Case A: a line is drawn, then another line, then the first line again with a
tiny character spacing (Tc 0.01). Only the first glyph of the second draw
lands exactly on the first draw.
Case B: a partial copy of a word ("S", then "ifi" placed where the word puts
those letters) is drawn, then another line, then the full word at the same
place. The full word's "S", "i", "f", "i" land exactly on the partial copy.
"""
from importlib.metadata import version
from pathlib import Path
from docling_parse.pdf_parser import DecodeConfig, DoclingPdfParser
OPS = """\
BT /F1 12 Tf 72 700 Td (ENFORCED FOR ALL ACCESS) Tj ET
BT /F1 12 Tf 72 680 Td (Another line in between) Tj ET
BT /F1 12 Tf 0.01 Tc 72 700 Td (ENFORCED FOR ALL ACCESS) Tj 0 Tc ET
BT /F1 12 Tf 72 600 Td (S) Tj ET
BT /F1 12 Tf 99.348 600 Td (ifi) Tj ET
BT /F1 12 Tf 72 580 Td (Another line in between) Tj ET
BT /F1 12 Tf 72 600 Td (Specifies that the row permission is enabled) Tj ET
"""
def write_pdf(path: Path) -> None:
objects = [
"<< /Type /Catalog /Pages 2 0 R >>",
"<< /Type /Pages /Kids [3 0 R] /Count 1 >>",
"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R "
"/Resources << /Font << /F1 5 0 R >> >> >>",
f"<< /Length {len(OPS)} >>\nstream\n{OPS}endstream",
"<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica "
"/Encoding /WinAnsiEncoding >>",
]
out = b"%PDF-1.4\n"
offsets = []
for number, body in enumerate(objects, 1):
offsets.append(len(out))
out += f"{number} 0 obj\n{body}\nendobj\n".encode()
xref = len(out)
out += f"xref\n0 {len(objects) + 1}\n0000000000 65535 f \n".encode()
out += b"".join(f"{o:010d} 00000 n \n".encode() for o in offsets)
out += (
f"trailer\n<< /Size {len(objects) + 1} /Root 1 0 R >>\n"
f"startxref\n{xref}\n%%EOF\n"
).encode()
path.write_bytes(out)
def main() -> None:
print(f"docling-parse {version('docling-parse')}")
pdf = Path("dedup_drops_letters.pdf")
write_pdf(pdf)
configs = {
"DecodeConfig()": DecodeConfig(),
"DecodeConfig(do_remove_duplicate_cells=False)": DecodeConfig(
do_remove_duplicate_cells=False
),
}
for name, config in configs.items():
doc = DoclingPdfParser(loglevel="fatal").load(pdf, decode_config=config)
page = doc.get_page(1)
print(f"\n[{name}]")
for line in page.textline_cells:
print(f" y={line.rect.r_y0:6.1f} {line.text!r}")
doc.unload()
if __name__ == "__main__":
main()
Expected: both draws of ENFORCED FOR ALL ACCESS read in full (or the second removed as a copy), and the full line reads Specifies that the row permission is enabled.
Observed on 7.27.1 (7.26.0 and 7.27.0 print the same):
docling-parse 7.27.1
[DecodeConfig()]
y= 697.5 'ENFORCED FOR ALL ACCESS'
y= 677.5 'Another line in between'
y= 697.5 'NFORCED FOR ALL ACCESS'
y= 597.5 'S ifi'
y= 577.5 'Another line in between'
y= 597.5 'pec es that the row permission is enabled'
[DecodeConfig(do_remove_duplicate_cells=False)]
y= 697.5 'ENFORCED FOR ALL ACCESS'
y= 677.5 'Another line in between'
y= 697.5 'ENFORCED FOR ALL ACCESS'
y= 597.5 'S ifi'
y= 577.5 'Another line in between'
y= 597.5 'Specifies that the row permission is enabled'
Observed on 7.25.0. 7.25.0 has no do_remove_duplicate_cells field, so both runs use its default:
docling-parse 7.25.0
[DecodeConfig()]
y= 697.5 'ENFORCED FOR ALL ACCESS'
y= 677.5 'Another line in between'
y= 697.5 'ENFORCED FOR ALL ACCESS'
y= 597.5 'S ifi'
y= 577.5 'Another line in between'
y= 597.5 'Specifies that the row permission is enabled'
On Docling's public fixture (tests/data/pdf/sources/redp5110_sampled.pdf in docling-project/docling):
from docling_parse.pdf_parser import DoclingPdfParser
page = DoclingPdfParser().load("redp5110_sampled.pdf").get_page(10)
print([c.text for c in page.textline_cells if "abled" in c.text or "FORCED" in c.text])
7.25.0 ['ENFORCED FOR ALL ACCESS', 'ENFORCED FOR ALL ACCESS', 'Specifies that the row permission is to be initially enabled', 'Specifies that the row permission is to be initially disabled']
7.26.0 ['ENFORCED FOR ALL ACCESS', 'NFORCED FOR ALL ACCESS', 'Specifies that the row permission is to be initially enabled', 'pecifies that the row permission is to be initially sabled']
7.27.1 ['ENFORCED FOR ALL ACCESS', 'NFORCED FOR ALL ACCESS', 'Specifies that the row permission is to be initially enabled', 'pecifies that the row permission is to be initially sabled']
On that page, a char-level diff of dedup off against dedup on (7.27.1) shows 10 removed glyphs. Six of them are a full second copy of the word ENABLE, which is correct. The other four are letters cut out of real text: the E of the second ENFORCED, and the S, d and i of Specifies … disabled.
Cause
#367 added an exact-match pass at the top of remove_duplicate_cells. It removes a later glyph whose text, font name and all eight rotated corner coordinates equal any earlier glyph's, wherever the two fall in the content stream. The first one stays.
decode_page runs it on the page's char cells whenever do_remove_duplicate_cells is true (the default):
This pass decides glyph by glyph. Nothing checks that the rest of the word or line is also a copy. Two cases follow.
- Case A, near-duplicate line. The second draw coincides exactly at the first glyph only. That glyph goes. The other glyphs differ by a few hundredths of a point. The tolerant pass below it does not reach them, because it stops scanning at the first cell on another line (
cells.h#L1603-L1606), and the copy is not next to the original in the content stream. Then the line-level passremove_overlapping_text_cells(cells.h#L1622-L1696, called fromcreate_word_cellsandcreate_line_cellsatcells.h#L1483-L1486and#L1496-L1499) only matches cells with equal full text (cells.h#L1657-L1658).NFORCED FOR ALL ACCESSno longer equalsENFORCED FOR ALL ACCESS, so both lines survive, one with a hole. - Case B, partial copy first. A partial copy of the text is drawn before the full text. The full text loses every glyph that lands exactly on the partial copy, because the partial copy comes first and is kept. On
redp5110_sampled.pdfp10 the partial copy is the line drawn earlier as thin clipped strips.
Before #367, only the tolerant pass existed, and it only compared cells that are next to each other on the same line in the content stream. So copies separated by another line were never compared. One note: when the partial copy comes directly before the full word, 7.25.0 already drops the same letters (I checked by removing the "Another line in between" draws from the script). #367 extends glyph-level matching to copies anywhere on the page.
Whether a letter is dropped also depends on exact floating-point equality. When I placed the partial "ifi" with a TJ offset instead of Td, its x came out as 99.34800000000001 against 99.348 in the full word. Those letters were kept and only the "S" was dropped.
What I tried (measured, not a patch)
I built v7.27.1 from source with small changes to remove_duplicate_cells and decoded Docling's PDF fixtures plus the regression PDFs (4,622 pages). None of these is a clean fix, so I am not proposing one.
- Remove the page-wide exact pass (keep the tolerant pass and
remove_overlapping_text_cells). Both synthetic cases and both lines onredp5110_sampled.pdfp10 come out whole, andtests/test_unit_overprinted_text.pystill passes. But duplicates return: the second copy ofENABLEon p10 is no longer removed, and 5 other pages keep repeated fragments (CJK newspaper pages, a repeated headline). - Drop a glyph only when its whole run is a copy. The result depends on what a run is. With runs built from geometry (same font and baseline, adjacent glyphs), p10 is fixed and
ENABLEis still removed, but 4 to 5 other pages change, because a copy and its original merge into one run that only partly matches. With one text-showing operator (Tj/TJ) as a run, no other page changes, but p10 still readspecifies … sabled: that line is drawn as thin clipped strips, soS,dandiare each whole operators that repeat an earlier strip.
Speed is not an issue for any of these: the duplicate-removal step is about 1% of decode time, and total decode time stayed within run-to-run noise (about 0.5 s on 440 pages).
So the case on p10 needs something that understands text redrawn under clips, not only glyph or operator matching.
Versions
- docling-parse 7.25.0, 7.26.0, 7.27.0, 7.27.1 (PyPI wheels, macOS arm64). Cited lines are at
971e3596(tagv7.27.1), which is alsomainHEAD as of 2026-11-23. - Python 3.14.6 (7.25.0, 7.26.0, 7.27.0) and 3.12.13 (7.27.1)
- macOS 27.2.1, arm64
Found, reproduced and drafted with an AI coding agent (Claude Code); reviewed before filing.
- Lenguaje dominante
- C++
- Estrellas
- 352
- Forks
- 99
- Merge medio
- 1 d 21 h
- PR fusionados (30 d)
- 37
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de docling-project/docling-parse
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
docling-project/docling-parse#448 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 74/100
docling-project/docling-parse#492 ·
Los mantenedores suelen responder en 1 día
-
7.25.0 splits letter-spaced CJK runs of two to four characters into one word per character (`股本重組` -> `股 本 重 組`): `infer_unspaced_gap_profile()` needs four gaps before it sees trackingPosiblemente ocupada @jjohnnystwsss la tomó hace 4 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
docling-project/docling-parse#483 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
docling-project/docling-parse#482 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
docling-project/docling-parse#473 ·
Los mantenedores suelen responder en 1 día
Todos los issues de docling-project/docling-parse
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
Los mantenedores suelen responder en 2 días
-
Missing repro Platform: Android
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
software-mansion/react-native-reanimated#11554 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Niko1221/Strata#7211 · 3 comentarios ·
Los mantenedores suelen responder en 5 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
sleepyviper1213/redis#52 ·