Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/d1d36a9d39e36a9ffa57a8d184bc9692 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/d1d36a9d39e36a9ffa57a8d184bc9692 to your computer and use it in GitHub Desktop.
Convert Word to Markdown and Markdown to Word in Python

You can convert DOCX to MD and MD to docx online in Python programmatically on the cloud. In this article, we will learn how to convert Word to Markdown and Markdown to Word in Python.

The following topics shall be covered in this article:

  1. Python Word to Markdown and Markdown to Word Converter Library
  2. Convert Word Document to Markdown in Python using REST API
  3. Convert Markdown to Word Online in Python using REST API
  4. Convert Specific Pages of Markdown to Word in Python using REST API
# How to Convert Markdown to Word Online in Python using REST API
try:
# Create an instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Define convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.storage_name = storage_name
settings.file_path = "python-testing/input-sample-file.md"
settings.format = "docx"
settings.output_path = "python-testing/output-sample-file.docx"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted MD to DOC online in Python: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# How to Convert Specific Pages of Markdown to Word using Python
try:
# Create an instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Define convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.storage_name = storage_name
settings.file_path = "python-testing/input-sample-file.md"
settings.format = "docx"
convertOptions = groupdocs_conversion_cloud.DocxConvertOptions()
convertOptions.from_page = 1
convertOptions.pages_count = 2
settings.convert_options = convertOptions
settings.output_path = "python-testing/output-sample-file.docx"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted MD to Docx online in Python: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# How to Convert Word Document to Markdown in Python using REST API
try:
# Create an instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Define convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.storage_name = storage_name
settings.file_path = "python-testing/input-sample-file.docx"
settings.format = "md"
loadOptions = groupdocs_conversion_cloud.DocxLoadOptions()
loadOptions.password = "password"
settings.load_options = loadOptions
settings.output_path = "python-testing/output-sample-file.md"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted Docx to Markdown online in Python: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import Python SDK in your python application from http://api.groupdocs.cloud
import groupdocs_conversion_cloud
# Get client_id and client_secret from https://dashboard.groupdocs.cloud after free registration.
client_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Get File API configurations
configuration = groupdocs_conversion_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
storage_name = "InternalStorage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment