LaTeX: CMYK JPEG figures are dropped
Bug
An \includegraphics figure that is a CMYK JPEG is added as a picture without an image. The conversion reports SUCCESS. The only trace is a debug log:
Could not load image cmyk.jpg: cannot write mode CMYK as PNG
RGB figures in the same document are kept.
The includegraphics branch in docling/backend/latex/handlers/macros.py passes the opened file straight to ImageRef.from_pil, which stores the image as PNG. Pillow cannot write CMYK as PNG, and the except Exception around the block turns the error into a debug log.
The XLSX (#4664), OpenDocument (#4666), DOCX and PPTX backends already pass pictures through normalize_image_for_png before ImageRef.from_pil. The LaTeX handler does not.
Steps to reproduce
from pathlib import Path
from PIL import Image
from docling.document_converter import DocumentConverter
Image.new("RGB", (200, 100), "blue").save("rgb.jpg")
Image.new("CMYK", (200, 100), (0, 255, 255, 0)).save("cmyk.jpg")
Path("paper.tex").write_text(
"\\documentclass{article}\n\\usepackage{graphicx}\n\\begin{document}\n"
"\\includegraphics{rgb.jpg}\n\\includegraphics{cmyk.jpg}\n\\end{document}\n"
)
result = DocumentConverter().convert(Path("paper.tex"))
print(result.status, [p.image is not None for p in result.document.pictures])
# ConversionStatus.SUCCESS [True, False], expected [True, True]
The source is a Path on purpose: with a str source no figure gets an image at all (#4694).
Docling version
main at 3181d9f (2.135.0)
Python version
Python 3.12.13, Pillow 12.3.0
I have a fix with a test, PR coming.