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/0f5ddeb5d0354d0170c98ac9f6fbbc29 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/0f5ddeb5d0354d0170c98ac9f6fbbc29 to your computer and use it in GitHub Desktop.
Convert Word to HTML Online in Python

You can convert Word DOCX to HTML format programmatically on the cloud. In this article, you will learn how to convert Word to HTML File in Python using REST API.

The following topics are covered in this article:

  • Convert Word to HTML Online in Python
  1. Word to HTML Conversion REST API and Python SDK
  2. Convert Word to HTML using REST API in Python
  3. Word to HTML Conversion without using Cloud Storage
  4. How to Convert Word to HTML and Download Directly
# How to Convert Word to HTML in Python
# Create necessary API instances
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Prepare convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.file_path = "python-testing/sample-word.docx"
settings.format = "html"
settings.output_path = "python-testing"
# Html convert options
convertOptions = groupdocs_conversion_cloud.HtmlConvertOptions()
convertOptions.from_page = 1
convertOptions.pages_count = 1
settings.convert_options = convertOptions
# Create convert document request
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
# Convert pages of Word to HTML file
result = convert_api.convert_document(request)
print("Converted range of pages from Word to HTML web page: " + result[0].path)
# 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 = "LocalStorage"
# How to Convert Word to HTML and Download Directly
# Create necessary API instances
import shutil
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Prepare convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.file_path = "python-testing/sample-word.docx"
settings.format = "html"
# output as document IOStream
settings.output_path = None
# Prepare convert request
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
# Convert Word to HTML file Directly
response = convert_api.convert_document_download(request)
# Move downloaded file to your working directory
shutil.move(response, "H:\\groupdocs-cloud-data\\")
# API initialization to download converted file
import shutil
file_api = groupdocs_conversion_cloud.FileApi.from_config(configuration)
# Create download file request
request = groupdocs_conversion_cloud.DownloadFileRequest("python-testing\\sample-word.html", storage_name)
# Download converted file
response = file_api.download_file(request)
# Move the downloaded file to your directory
shutil.move(response, "H:\\groupdocs-cloud-data\\")
# Upload word file to cloud storage
# Create an instance of the file API
file_api = groupdocs_conversion_cloud.FileApi.from_config(configuration)
# Call upload file request
request = groupdocs_conversion_cloud.UploadFileRequest("python-testing\sample-word.docx", "H:\\groupdocs-cloud-data\\word-file.docx", storage_name)
# Upload docx file to the cloud
response = file_api.upload_file(request)
print(response.uploaded)
# Word to HTML Conversion without using cloud storage
# Create necessary API instances
import shutil
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Prepare convert request
request = groupdocs_conversion_cloud.ConvertDocumentDirectRequest("html", "H:\\groupdocs-cloud-data\\word-file.docx")
# Convert Word to HTML without cloud storage
response = convert_api.convert_document_direct(request)
# Move downloaded file to your working directory
shutil.move(response, "H:\\groupdocs-cloud-data\\")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment