Skip to content

HTML, Markdown, AsciiDoc, JATS and MHTML conversions fail on CMYK, LAB and F mode pictures #4682

Open

Description

@ryanmeowy

Bug

A picture whose color mode cannot be written as PNG aborts the whole conversion. This affects the HTML, Markdown, AsciiDoc, JATS and MHTML backends.

The modes that fail are CMYK, LAB and F. They are common in print-scanned documents and in TIFF files. A truncated or unreadable image file fails in the same way.

The shared loader docling/backend/utils/image_resource_loader.py writes each picture to PNG through ImageRef.from_pil(). Pillow cannot write these modes as PNG, so from_pil() raises OSError: cannot write mode CMYK as PNG. The except tuple in create_image_ref() does not list OSError, so the error escapes and aborts the conversion.

The Word (#4598), PowerPoint (#4586) and Excel (#4664) backends call normalize_image_for_png() before from_pil(). The shared loader does not, although five backends use it.

The observed behavior differs by backend:

Backend Behavior
HTML, Markdown, AsciiDoc The conversion fails with RuntimeError: Pipeline SimplePipeline failed.
JATS The conversion reports success. The figure is dropped. All body content after the figure is lost.
MHTML The conversion reports success. The picture is dropped silently.

The JATS case is the most severe. docling/backend/xml/jats_backend.py wraps the body walk in a bare except Exception: and logs only the traceback. One bad figure stops the body walk, so all text after the figure is lost. The caller sees a successful status.

The code in html_backend.py already states the intended behavior:

The source is not loaded, but the picture is kept, as for an image file that cannot be read.

The current behavior does not match that intent for the text backends.

Steps to reproduce

python3 -c "from PIL import Image; Image.new('CMYK', (100, 50), (0, 255, 255, 0)).save('/tmp/p.jpg', 'JPEG')"
printf '<html><body><p>text</p><img src="p.jpg"></body></html>' > /tmp/p.html
docling /tmp/p.html

Result: the conversion fails.

Full error chain:

OSError: cannot write mode CMYK as PNG
  PngImagePlugin._save
  docling_core.types.doc.ImageRef.from_pil
  docling.backend.utils.image_resource_loader.ImageResourceLoader.create_image_ref
RuntimeError: Pipeline SimplePipeline failed
  docling.pipeline.simple_pipeline

Expected result: the picture is kept, or the conversion keeps the picture placeholder and emits a warning. This is the behavior that html_backend.py documents, and the behavior that the office backends already have.

Docling version

Docling version: 2.135.0
Docling Core version: 2.100.0
Docling IBM Models version: 4.0.3
Docling Parse version: 7.22.2

Python version

Python 3.13.15 (cpython-313)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions