GroupDocs.Markdown provides two ways to load a file from a local disk: the static one-liner API and the instance-based API.
Using static method
The simplest approach – pass a file path and get the Markdown string back:
fromgroupdocs.markdownimportMarkdownConverterdefload_from_disk_static():"""Load and convert a local file to Markdown using the static API."""# Step 1: Convert a local file to a Markdown string in one callmarkdown=MarkdownConverter.to_markdown("business-plan.docx")# Step 2: Or save the result directly to a file on diskMarkdownConverter.to_file("business-plan.docx","load-from-disk-static.md")if__name__=="__main__":load_from_disk_static()
business-plan.docx is sample file used in this example. Click here to download it.
| , create a MarkdownConverter instance:
fromgroupdocs.markdownimportMarkdownConverterdefload_from_disk_instance():"""Load a local file with the instance API, inspect metadata, then convert."""# Step 1: Open the document with a context managerwithMarkdownConverter("business-plan.docx")asconverter:# Step 2: Retrieve document metadata before convertinginfo=converter.get_document_info()print(f"Format: {info.file_format}, Pages: {info.page_count}")# Step 3: Convert to Markdown and print the resultconverter.convert("load-from-disk-instance.md")if__name__=="__main__":load_from_disk_instance()
business-plan.docx is sample file used in this example. Click here to download it.
| ![Woman with laptop and business documents](data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA3ADcAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wAARCAHyAqYDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIW
[TRUNCATED]