This article provides a guide on how to convert Word page to image with Python REST API. It will teach you to automatically transform a Word page to JPG with Python REST API using the Python cloud SDK. No other third-party Word file processor or image-processing software is required to perform this task.
Prerequisite
- Create an account and get API credentials
- Download Aspose.Words Cloud SDK for Python to render a Word file page
- Setup Python solution project with the above SDK for saving a page as an image
Steps to Convert Word Page to Image with Python REST API
- Initialize the WordsApi class object with client ID and client secret for rendering a page
- Create an object of the RenderPageOnlineRequest class
- Read the source Word file into the request object
- Set the page index and output image format
- Call the RenderPageOnline() method to render the desired page
- Save the output image from the response object
The above steps have summarized how to convert Word page into image with Python REST API. You need to instantiate the objects of WordsApi and RenderPageOnlineRequest classes by setting the desired values. Finally, call the RenderPageOnline() method to save the target page as an image in the desired format.
Code to Convert Word Page to JPG with Python REST API
This sample code exhibits how to convert Word page to image with Python REST API. You may set the desired page index starting from 1 instead of 0. The response object is a stream that you may save on the disk.
This article has guided us on how to make a Word DOC a picture with Python REST API. If you want to convert the complete Word file to an image, refer to the following article: Convert DOCX to JPG with Python REST API.