When the source document is not a file on disk (e.g., downloaded from a network, read from a database, or received as an upload), you can pass a binary stream directly to the MarkdownConverter constructor.
The stream is copied internally, so you may close it immediately after creating the converter.
fromgroupdocs.markdownimportMarkdownConverterdefload_from_stream():"""Load a document from a binary stream and convert to Markdown."""# Step 1: Open the document file as a binary streamwithopen("business-plan.docx","rb")asstream:# Step 2: Create a converter from the streamwithMarkdownConverter(stream)asconverter:# Step 3: Convert and save the Markdown outputconverter.convert("load-from-stream.md")if__name__=="__main__":load_from_stream()
business-plan.docx is sample file used in this example. Click here to download it.
| :"""Load a document from a stream with explicit format specification."""# Step 1: Open the file as a binary streamwithopen("document","rb")asstream:# Step 2: Specify the file format explicitly (no auto-detection)load_options=LoadOptions(FileFormat.DOCX)# Step 3: Create a converter from the stream with load optionswithMarkdownConverter(stream,load_options=load_options)asconverter:# Step 4: Convert and save the Markdown outputconverter.convert("load-from-stream-options.md")if__name__=="__main__":importshutilshutil.copy("business-plan.docx","document")# create file without extensionload_from_stream_with_options()
| ![Woman with laptop and business documents](data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA3ADcAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wAARCAHyAqYDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIW
[TRUNCATED]