How to Convert Keynote KEY to JPG in Python

Converting Mac formats into something more convenient is a difficult and time consuming process at the best of times. I’m sure that you already are aware of this, but you should also know that it doesn’t have to be. In today’s post, we will take a couple minutes to demonstrate how to get this done very quickly indeed.

To begin with, we will need our client to be installed.

pip install cloudmersive-convert-api-client

Now we can access our library and call convert_document_keynote_to_jpg, as you see below:

from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom cloudmersive_convert_api_client.rest 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.quality = 56 # int | Optional; Set the JPEG quality level; lowest quality is 1 (highest compression), highest quality (lowest compression) is 100; recommended value is 75. Default value is 75. (optional)try:# Convert Keynote Presentation (KEY) to JPG/JPEG image arrayapi_response = api_instance.convert_document_keynote_to_jpg(input_file, quality=quality)pprint(api_response)except ApiException as e:print("Exception when calling ConvertDocumentApi->convert_document_keynote_to_jpg: %s\n" % e)

And that’s really all that you have to do. If you run this code, you will see that you are returned an array of JPG images, with one for each page in your Keynote presentation. Each JPG is provided as a byte array, making it super easy to work with on your end.

Image for post
Image for post

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