Skip to content

HTML and Markdown conversion fails on a CMYK or truncated image #4680

Open

Description

@usmanmateen

Bug

With fetch_images=True, a single CMYK image in an HTML or Markdown file makes the whole conversion fail with cannot write mode CMYK as PNG, so none of the document's text comes through. A truncated image fails the same way (Truncated File Read).

ImageResourceLoader.create_image_ref passes the image to ImageRef.from_pil without normalize_image_for_png (the helper #4598 added for Word and PowerPoint), and PNG can't store CMYK. Its except catches UnidentifiedImageError, ValueError and others, but not OSError, which is what Pillow raises here and for a truncated file. So the error ends the conversion instead of becoming a warning like the other image errors.

Steps to reproduce

import base64
from io import BytesIO

from PIL import Image

from docling.datamodel.backend_options import HTMLBackendOptions
from docling.datamodel.base_models import InputFormat
from docling.document_converter import DocumentConverter, HTMLFormatOption

jpeg = BytesIO()
Image.new("CMYK", (200, 100), (0, 255, 255, 0)).save(jpeg, format="JPEG")
src = "data:image/jpeg;base64," + base64.b64encode(jpeg.getvalue()).decode()
with open("cmyk.html", "w") as f:
    f.write(f'<p>Some text</p><img src="{src}">')

converter = DocumentConverter(
    format_options={
        InputFormat.HTML: HTMLFormatOption(
            backend_options=HTMLBackendOptions(fetch_images=True)
        )
    }
)
result = converter.convert("cmyk.html", raises_on_error=False)
print(result.status, [e.error_message for e in result.errors])
# ConversionStatus.FAILURE ['cannot write mode CMYK as PNG']

The same image in RGB converts with SUCCESS. Markdown (![pic](data:image/jpeg;base64,...) with MarkdownBackendOptions(fetch_images=True)) fails the same way.

Docling version

main at 9590eb4 (the code is the same in 2.135.0)

Python version

Python 3.12.13

I have a fix with tests, PR coming.

Activity

  1. ceberam commented on Oct 8, 2026

    @ceberam
    Member

    Duplicate of #4682

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