docling icon indicating copy to clipboard operation
docling copied to clipboard

so im extracting the picture item and sending that to llm to extract the text from it

Open madmaxtwentytwo opened this issue 1 year ago • 3 comments

is there any way that i can replace that specific picture item with the extracted text tell me how can we do it give me code samples for it

madmaxtwentytwo avatar Aug 26 '25 06:08 madmaxtwentytwo

Yes, you can replace a picture item in a Docling document with the extracted text from your LLM. The typical workflow is: iterate over the document items, identify the PictureItem, extract the text, create a new TextItem, and use the document's replace_item method to swap them. Here’s a code sample that demonstrates this pattern (source):

from docling_core.types.doc.document import PictureItem, TextItem, DocItemLabel

replacements = []
for item, _ in doc.iterate_items():
    if isinstance(item, PictureItem):
        # Assume you already have the extracted text for this image
        extracted_text = "your LLM result here"
        # Optionally preserve provenance
        prov = item.prov[0] if isinstance(item.prov, list) and item.prov else None
        new_text = doc.add_text(
            label=DocItemLabel.TEXT,
            text=extracted_text,
            prov=prov,
        )
        replacements.append((item, new_text))

for old_item, new_item in replacements:
    doc.replace_item(new_item=new_item, old_item=old_item)

This will replace each PictureItem with a new TextItem containing your extracted text. If you want to keep the image but add the text as a caption or annotation (so it appears in markdown export), you can append a description annotation to the PictureItem instead (source).

If you want the extracted text to appear in the markdown output instead of the image, export with image_mode='placeholder' and include_annotations=True (source).

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about docling Share Dosu with your team

dosubot[bot] avatar Aug 26 '25 06:08 dosubot[bot]

Hi @madmaxtwentytwo, dosubot suggested an answer above but there's been no confirmation either way. Did that resolve it for you, or should this stay open? If we don't hear back within a week, we'll close it. Feel free to reopen if you see a need.

cau-git avatar Sep 01 '26 14:09 cau-git

Closing this issue because we did not hear back after our check-in on September 1. If it is still relevant for you, please reopen it or open a new issue with a current Docling version and a reproducer. Thanks!

cau-git avatar Oct 14 '26 13:10 cau-git