From 8d356aa24715433d458eff4f5f0937ff5cb9cc69 Mon Sep 17 00:00:00 2001 From: Michele Dolfi <97102151+dolfim-ibm@users.noreply.github.com> Date: Thu, 24 Oct 2024 20:19:41 +0200 Subject: [PATCH] docs: add export with embedded images (#175) Signed-off-by: Michele Dolfi --- docs/examples/export_figures.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/examples/export_figures.py b/docs/examples/export_figures.py index d8aafa98..3f0bfa84 100644 --- a/docs/examples/export_figures.py +++ b/docs/examples/export_figures.py @@ -2,7 +2,7 @@ import time from pathlib import Path -from docling_core.types.doc import PictureItem, TableItem +from docling_core.types.doc import ImageRefMode, PictureItem, TableItem from docling.datamodel.base_models import FigureElement, InputFormat, Table from docling.datamodel.pipeline_options import PdfPipelineOptions @@ -71,6 +71,12 @@ def main(): with element_image_filename.open("wb") as fp: element.image.pil_image.save(fp, "PNG") + # Save markdown with embedded pictures + content_md = conv_res.document.export_to_markdown(image_mode=ImageRefMode.EMBEDDED) + md_filename = output_dir / f"{doc_filename}-with-images.md" + with md_filename.open("w") as fp: + fp.write(content_md) + end_time = time.time() - start_time _log.info(f"Document converted and figures exported in {end_time:.2f} seconds.")