qpdj_obj is unknown when a fonts /ToUnicode is not a stream

Abierto
#447 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 5 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
58/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
cpp
Área
backend

Línea de trabajo

The report includes a minimal PDF reproduction and points to page_font.h, specifically the final else in init_cmap. Start by reading that function and the font parsing tests, then run the reproduction with the supplied PDF. Done means the page parses and returns Hello when /ToUnicode refers to a non-stream object; the suggested fix in the issue is unverified.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Hello. I ran into a fun edge case today on one of my documents. It looks like when a fonts /ToUnicode entry is not a tsream or a name, the page gets dropped, which shows up downstream as "Page N failed to parse".

I believe this is an edge case but here is a minimal reproduction:

from docling_parse.pdf_parser import DoclingPdfParser
 
content = b"BT /F1 12 Tf 20 50 Td (Hello) Tj ET"
objects = [
    b"<< /Type /Catalog /Pages 2 0 R >>",
    b"<< /Type /Pages /Kids [3 0 R] /Count 1 >>",
    b"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 200 100]"
    b" /Resources << /Font << /F1 5 0 R >> >> /Contents 4 0 R >>",
    b"<< /Length %d >>\nstream\n%s\nendstream" % (len(content), content),
    b"<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica /ToUnicode 6 0 R >>",
    b"<< /MCID 4 >>", 
]
 
pdf = bytearray(b"%PDF-1.4\n")
offsets = []
for i, obj in enumerate(objects, start=1):
    offsets.append(len(pdf))
    pdf += b"%d 0 obj\n%s\nendobj\n" % (i, obj)
xref = len(pdf)
pdf += b"xref\n0 %d\n0000000000 65535 f \n" % (len(objects) + 1)
pdf += b"".join(b"%010d 00000 n \n" % off for off in offsets)
pdf += b"trailer\n<< /Size %d /Root 1 0 R >>\nstartxref\n%d\n%%%%EOF\n" % (len(objects) + 1, xref)
 
with open("repro_tounicode.pdf", "wb") as f:
    f.write(pdf)
 
page = DoclingPdfParser().load("repro_tounicode.pdf").get_page(1)
# RuntimeError: qpdf_obj is unknown: 6 0 R
print([cell.text for cell in page.textline_cells])  # expected: ['Hello']

That same pdf gets read by pypdfium2.PdfDocument(BytesIO(pdf)[0].get_textpage().get_text_range()

I get this on docling-parse 7.22.2 and latest (7.24.2).

Claude Recommended Fix

In page_font.h, in the final else of init_cmap, set cmap_initialized = false, this way parsed fonts are unaffected

Lenguaje dominante
C++
Estrellas
346
Forks
92
Merge medio
4 d 3 h
PR fusionados (30 d)
26

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de docling-project/docling-parse

Todos los issues de docling-project/docling-parse

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.