This article elaborates on how to convert XPS to Image in Python. It encompasses the step-by-step workflow and a runnable code to export XPS to JPG in Python. Moreover, it also covers different properties to customize the process as per your requirements.
Steps to Convert XPS to Image in Python
- Set up the environment by installing Aspose.Page for converting XPS files
- Load XPS document using a stream or file using the XpsDocument class
- Initialize PngSaveOptions class object
- Create a rendering device for the image
- Iterate through document partitions and write the output image
These steps summarize the details to convert XPS file to JPG in Python. Quickly load the input XPS file from the disk or stream and set the required parameters. Finally, render the output image in your preferred file format like JPG, PNG, etc.
Code to Export XPS to PNG in Python
This sample code depicts which methods and properties you can set to render XPS to PNG in Python. It primarily works with the XpsDocument class to load the source file. Subsequently, before exporting the generated image, various custom properties can be set using the PngSaveOptions class, such as smoothing mode, resolution, specific page numbers, etc.
This tutorial has explained the information on exporting XPS to Image in Python. Whereas, if you are interested in converting EPS to Image format then head to the article on Convert EPS to Image in Python.