docling-project/docling

Add image_dir parameter to export_to_markdown for automatic image saving

Open

#3.094 aberto em 9 de mar. de 2026

Ver no GitHub
 (3 comments) (1 reaction) (0 assignees)Python (4.140 forks)batch import
docling-documentenhancementgood first issue

Métricas do repositório

Stars
 (59.751 stars)
Métricas de merge de PR
 (Mesclagem média 7d 5h) (93 fundiu PRs em 30d)

Description

Problem

When using ImageRefMode.REFERENCED, users must manually:

  1. Iterate through all picture elements
  2. Save each image to disk
  3. Update the URI for each element
  4. Then call export_to_markdown()

Proposed Solution

Add optional image_dir and image_path_prefix parameters to export methods:

markdown = doc.export_to_markdown(
    image_mode=ImageRefMode.REFERENCED,
    image_dir=Path("./output/images"),
    image_path_prefix="images/"  # relative path in markdown output
)

When image_dir is provided:

  • Automatically save images to that directory
  • Generate sequential filenames (e.g. image_001.png)
  • Use image_path_prefix in the markdown output

Affected Methods

  • DoclingDocument.export_to_markdown()
  • PictureItem.export_to_markdown()
  • Potentially HTML export methods too

Would this be an interesting feature to have? Happy to submit a PR.

(PS: Keep up the great work!!)

Guia do colaborador