Convert Word to JPEG, PNG, or GIF Image File in Python

Convert Word to JPEG, PNG, or GIF Image File in Python
Convert Word to JPEG, PNG, or GIF Image File in Python

Word is one of the popular formats for sharing and printing documents. We often need to convert word documents to different image formats. It is better to use already developed specialized tools that provide an easily maintainable, flexible conversion solution to your needs. In this article, we will learn how to convert word to JPEG, PNG, or GIF image file in Python.

The following topics shall be covered in this article:

Word to Images Conversion REST API – Python SDK

For converting JPGPNG and GIF images in Python, we will be using the Ruby SDK of GroupDocs.Conversion Cloud API. Python SDK of GroupDocs.Conversion provides the best way to convert Word DOCX to JPG, PNG and GIF files in seconds. It is 100% free, secure and easy to use Python SDK for files conversion. It allows converting documents of supported formats to image programmatically on the cloud. You can install it using the following command in the console:

pip install groupdocs_conversion_cloud

Firstly, get your Client ID and Secret from the dashboard before following the below mentioned steps. Once you have your ID and secret, add below code in your application as shown below:

How to Convert Word to JPEG using REST API in Python

You can convert Word to JPEG format programmatically by following the steps given below:

  • Firstly, create an instance of the ConvertApi
  • Next, create an instance of the ConvertSettings
  • Then, set the storage name and word file path
  • Set resultant image file format as “jpeg”
  • Create an instance of the DocxLoadOptions
  • Set the word file password and load_options
  • Create an instance of the JpegConvertOptions
  • Define the grayscale, from_page, pages_count, quality, rotate_angle and use_pdf etc
  • Set convertOptions to settings
  • Now, provide the output file path
  • After that, create ConvertDocumentRequest with ConvertSettings as argument
  • Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file

The following example code demonstrate how to convert word documents to JPEG image format using REST API in Python:

The above code sample will save the converted JPEG file on the cloud.

Convert DOC/DOCX to PNG in Python using REST API

You can also convert Word Doc/Docx to PNG file format programmatically by following the steps given below:

  • Create an instance of the ConvertApi
  • Next, create an instance of the ConvertSettings
  • Then, set the storage name and word file path
  • Also, set “png” as output image format
  • Create an instance of the DocxLoadOptions
  • Set the word file password and load_options
  • Create an instance of the PngConvertOptions
  • Define the grayscale, from_page, pages_count, quality, rotate_angle and use_pdf values
  • Set convertOptions to settings
  • Now, provide the output file path
  • After that, create ConvertDocumentRequest with ConvertSettings as argument
  • Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file

The following example code shows how to convert word to PNG format using REST API in Python:

Convert Word DOC/DOCX to GIF in Python using REST API

You can convert Word Docx to JPG programmatically by following the steps given below:

  • Create an instance of the ConvertApi
  • Next, create an instance of the ConvertSettings
  • Then, set the storage name and word file path
  • Now, provide “gif” as output image format
  • Create an instance of the DocxLoadOptions
  • Set the word file password and load_options
  • Create an instance of the GifConvertOptions
  • Define the grayscale, from_page, pages_count, quality, rotate_angle and use_pdf etc.
  • Set convertOptions to settings
  • Next, provide the output file path
  • After that, create ConvertDocumentRequest with ConvertSettings as argument.
  • Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file.

The following code sample shows how to convert word Doc/Docx to GIF image file format using REST API in Python:

Online Word to Image Converter for Free

Please try the following free online JPG, PNG and GIF conversion tool, which is developed using the above API.

Conclusion

In this article, we have learned how to convert word to image formats on the cloud. Now you know:

  • how to convert word documents to jpeg/jpg in Python;
  • how to convert word doc/docx to png image format using Python;
  • how to convert word doc/docx to gif file format in Python;

You can learn more about GroupDocs.Conversion Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.

Ask a question

If you have any questions about word docx to image converter, please feel free to ask us on the Free Support Forum.

See Also