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/e267c8dc0ae4fe457f10c6a00ee2585c to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/e267c8dc0ae4fe457f10c6a00ee2585c to your computer and use it in GitHub Desktop.
Convert Word DOCX to Jpeg/Jpg, Png or Gif in Python using Rest API.
# 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.jpeg", storage_name)
# Download converted file
response = file_api.download_file(request)
# Move the downloaded image jpeg file to your local directory
shutil.move(response, "H:\\groupdocs-cloud-data\\")
# Upload word .docx file to your 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)
# How to Convert Word DOCX to GIF using REST API in Python
# 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/sample-word.docx"
settings.format = "gif"
loadOptions = groupdocs_conversion_cloud.DocxLoadOptions()
loadOptions.password = "password"
settings.load_options = loadOptions;
convertOptions = groupdocs_conversion_cloud.GifConvertOptions()
convertOptions.gray_scale = True
convertOptions.from_page = 1
convertOptions.pages_count = 1
convertOptions.quality = 100
convertOptions.rotate_angle = 90
convertOptions.use_pdf = False
settings.convert_options = convertOptions
settings.output_path = "python-testing"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted Word to GIF format: " + str(response))

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

The following topics are covered in this article:

  1. Word to Images Conversion REST API - Python SDK
  2. How to Convert Word to JPEG using REST API in Python
  3. Convert DOC/DOCX to PNG in Python using REST API
  4. Convert Word DOC/DOCX to GIF in Python using REST API
  5. Online Word to Image Converter for Free
# How to Convert Word DOCX to JPEG using REST API in 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/sample-word.docx"
settings.format = "jpeg"
loadOptions = groupdocs_conversion_cloud.DocxLoadOptions()
loadOptions.password = "password"
settings.load_options = loadOptions;
convertOptions = groupdocs_conversion_cloud.JpegConvertOptions()
convertOptions.gray_scale = True
convertOptions.from_page = 1
convertOptions.pages_count = 1
convertOptions.quality = 100
convertOptions.rotate_angle = 90
convertOptions.use_pdf = False
settings.convert_options = convertOptions
settings.output_path = "python-testing"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted Word DOCX to JPEG image format: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# How to Convert Word DOCX to PNG using REST API in Python
# 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/sample-word.docx"
settings.format = "png"
loadOptions = groupdocs_conversion_cloud.DocxLoadOptions()
loadOptions.password = "password"
settings.load_options = loadOptions;
convertOptions = groupdocs_conversion_cloud.PngConvertOptions()
convertOptions.gray_scale = True
convertOptions.from_page = 1
convertOptions.pages_count = 1
convertOptions.quality = 100
convertOptions.rotate_angle = 90
convertOptions.use_pdf = False
settings.convert_options = convertOptions
settings.output_path = "python-testing"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted DOCX to PNG file format: " + str(response))
# 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 = "DefaultStorage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment