Save image as file

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Markdown MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-markdown -- dnx GroupDocs.Markdown.Mcp --yes
Folders, licensing and more →

Use ExportImagesToFileSystemStrategy to save images as separate files during conversion. The Markdown output will contain image references pointing to the exported files.

Basic usage

from groupdocs.markdown import MarkdownConverter, ConvertOptions, ExportImagesToFileSystemStrategy

def image_file_basic():
    """Save images to a folder on disk during PDF to Markdown conversion."""

    # Step 1: Configure the file system image export strategy
    options = ConvertOptions()
    options.image_export_strategy = ExportImagesToFileSystemStrategy("output/images")

    # Step 2: Convert and save to file using keyword argument for options
    MarkdownConverter.to_file("business-plan.pdf", "output/document.md", convert_options=options)

if __name__ == "__main__":
    import os
    os.makedirs("output/images", exist_ok=True)
    image_file_basic()

business-plan.pdf is sample file used in this example. Click here to download it.

output/document.md (7 KB)
output/images/img-001.png (3 KB)
output/images/img-002.jpg (73 KB)
output/images/img-003.jpg (76 KB)

Download full output

Using images_relative_path

By default, image references in the Markdown use the full images folder path. Set images_relative_path to produce portable, relative image links:

from groupdocs.markdown import MarkdownConverter, ConvertOptions, ExportImagesToFileSystemStrategy

def image_file_relative():
    """Save images to disk with portable, relative paths in the Markdown output."""

    # Step 1: Configure the image export strategy with a relative path
    strategy = ExportImagesToFileSystemStrategy("output/images")
    strategy.images_relative_path = "images"  # produces ![](images/img-001.png)

    # Step 2: Assign the strategy to conversion options
    options = ConvertOptions()
    options.image_export_strategy = strategy

    # Step 3: Convert and save using keyword argument for options
    MarkdownConverter.to_file("business-plan.pdf", "output/document.md", convert_options=options)

    # Markdown output contains: ![](images/img-001.png)
    # Image file saved to:     output/images/img-001.png

if __name__ == "__main__":
    import os
    os.makedirs("output/images", exist_ok=True)
    image_file_relative()

business-plan.pdf is sample file used in this example. Click here to download it.

output/document.md (7 KB)
output/images/img-001.png (3 KB)
output/images/img-002.jpg (73 KB)
output/images/img-003.jpg (76 KB)

Download full output