This guide shows you how to convert documents to Markdown with GroupDocs.Markdown for Python via .NET. You’ll have working code in under 2 minutes.
How it works
flowchart LR
A["Input Document\n(DOCX, PDF, XLSX, EPUB, ...)"]
B["MarkdownConverter"]
C["Markdown Output\n(.md file or string)"]
A --> B --> C
Prerequisites
Install the package from PyPI:
pip install groupdocs-markdown-net
Import the module:
fromgroupdocs.markdownimportMarkdownConverter
Example 1: Convert Word to Markdown
The simplest conversion – one line of code:
fromgroupdocs.markdownimportMarkdownConverterdefconvert_word_to_markdown():"""Convert a Word document to Markdown in one line of code."""# Step 1: Convert a DOCX file to a Markdown stringmarkdown=MarkdownConverter.to_markdown("business-plan.docx")# Step 2: Or save the result directly to a .md fileMarkdownConverter.to_file("business-plan.docx","convert-word.md")if__name__=="__main__":convert_word_to_markdown()
business-plan.docx is sample file used in this example. Click here to download it.
| :"""Convert a PDF to Markdown with images exported to a folder on disk."""# Step 1: Configure image export with relative pathsstrategy=ExportImagesToFileSystemStrategy("output/images")strategy.images_relative_path="images"# Step 2: Assign the strategy to conversion optionsoptions=ConvertOptions()options.image_export_strategy=strategy# Step 3: Convert and save using keyword argument for optionsMarkdownConverter.to_file("business-plan.pdf","output/report.md",convert_options=options)# Images saved to output/images/# Markdown references: if__name__=="__main__":importosos.makedirs("output/images",exist_ok=True)convert_pdf_with_images()
business-plan.pdf is sample file used in this example. Click here to download it.
Convert a spreadsheet with column truncation and front matter:
fromgroupdocs.markdownimportMarkdownConverter,ConvertOptions,MarkdownFlavordefconvert_excel_with_options():"""Convert an Excel spreadsheet with column/row limits, front matter, and GFM flavor."""# Step 1: Configure spreadsheet-specific conversion optionsoptions=ConvertOptions()options.max_columns=8# limit to first 8 columnsoptions.max_rows=50# limit to first 50 data rowsoptions.include_front_matter=True# add YAML metadata blockoptions.flavor=MarkdownFlavor.GIT_HUB# GitHub Flavored Markdown# Step 2: Open the spreadsheet with a context managerwithMarkdownConverter("cost-analysis.xlsx")asconverter:# Step 3: Inspect document metadata before convertinginfo=converter.get_document_info()print(f"Worksheets: {info.page_count}")# Step 4: Convert using keyword argument for optionsresult=converter.convert("convert-excel-options.md",convert_options=options)# Step 5: Check for non-fatal conversion warningsforwinresult.warnings:print(f"Warning: {w}")if__name__=="__main__":convert_excel_with_options()
cost-analysis.xlsx is sample file used in this example. Click here to download it.
---
title: "Cost Analysis"
author: "GroupDocs"
format: Xlsx
pages: 1
---
## Cost data and chart
...