ODS: pictures anchored to the sheet are dropped
Bug
Pictures anchored to an ODS sheet (stored in <table:shapes>) are dropped. The conversion reports SUCCESS, and the only trace is a debug log:
Could not extract image from ODS sheet: 'DrawImage' object has no attribute 'get_data'
Pictures anchored to a cell are kept, because the rich cell path adds them.
OdsDocumentBackend._find_images_in_sheet reads each picture with img.get_data(), but odfdo's DrawImage has no get_data() (checked in odfdo 3.22.0 and 3.26.3), so the call raises for every picture and the except hides it.
#4557 changed this function, but it was merged into a stacked branch that didn't reach main (#4553 was closed), so main still has the get_data() call.
Steps to reproduce
from odfdo import Document, Element, Frame, Table
from PIL import Image
from docling.document_converter import DocumentConverter
Image.new("RGB", (200, 100), "red").save("red.png")
doc = Document("spreadsheet")
doc.body.clear()
table = Table("Sheet1", width=2, height=2)
doc.body.append(table)
# A picture anchored to cell B2
cell = table.get_cell("B2")
cell.append(Frame.image_frame(doc.add_file("red.png"), size=("2cm", "1cm")))
table.set_cell("B2", cell)
# A picture anchored to the sheet, stored in <table:shapes>
shapes = Element.from_tag("table:shapes")
shapes.append(
Frame.image_frame(doc.add_file("red.png"), size=("2cm", "1cm"), position=("1cm", "1cm"))
)
table.insert(shapes, position=0)
doc.save("pictures.ods")
result = DocumentConverter().convert("pictures.ods")
print(result.status, len(result.document.pictures)) # ConversionStatus.SUCCESS 1, expected 2
Docling version
main at 9590eb4 (the code is the same in 2.135.0)
Python version
Python 3.12.13
I found this while working on #4666 and have a fix with tests, PR coming.