This article describes how to convert HTML to JPEG using Python REST API. You will learn to transform HTML to image using Python REST API by utilizing a Python-based Cloud SDK. It describes the complete process with the help of a set of programming instructions.
Prerequisite
- Create an account and get API credentials for generating an image of an HTML page
- Download Aspose.HTML Cloud SDK for Python to transform an HTML file to a JPEG file
- Set up a Python project with the above SDK
Steps to convert HTML to Image using Python RESTful Service
- Import the namespaces Aspose.HTML.Cloud.Sdk and Aspose.HTML.Cloud.Sdk.Conversion for using desired classes and methods
- Create an object of the HtmlApi class and set the Client ID and secret
- Instantiate an object of the ConverterBuilder class and set values for the from local file and to local file properties
- Invoke the ConvertAsync() with the above builder properties to perform the conversion
These steps summarize the process to change a file format from HTML to JPG using Python REST Interface. Import the namespaces for the required classes and methods, create an instance of the HtmlApi with client ID and secret, and get the ConvertApi object from it. Create an object of the ConverterBuilder class, set the local or cloud storage references for the input and output files, and call the ConvertAsync() method in the API to convert the file according to the configuration in the ConverterBuilder object.
Code to convert HTML to JPG using Python API
The above code demonstrates how to generate image from HTML using Python Low Code API. You can load required files from Cloud storage if already uploaded or created in the Cloud. Combination is also possible to set the source from local storage and output file on the local disk or vice versa.
This article has enlightened us on HTML to image conversion. To transform an HTML file to an MD file, refer to the article on Convert HTML to Markdown using Python REST API.