How to Convert ODT to PNG in Python

If you have ever tried your hand at converting document files into images, you probably know that a great deal of time is normally required, generally coming with a free side order of frustration. With that in mind, this post’s purpose is to get your conversion process set up super quick and easy. To do this, we shall make good use of a Cloudmersive API that can convert ODT documents into PNG images, with one for each page.

Let’s install our client now.

pip install cloudmersive-convert-api-client

Next our function call goes like this:

from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_convert_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_convert_api_client.ConvertDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))input_file = '/path/to/file' # file | Input file to perform the operation on.try:# Convert ODT Text File to PNG image arrayapi_response = api_instance.convert_document_odt_to_png(input_file)pprint(api_response)except ApiException as e:print("Exception when calling ConvertDocumentApi->convert_document_odt_to_png: %s\n" % e)

And you are officially done! Easy. The rest of this library covers a ton more other format conversions, so give it a look!

Image for post

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store