Convert XPS to PDF in Python

This article focuses on how to convert XPS to PDF in Python. It explains the stepwise algorithm and a code snippet to change XPS file to PDF in Python. You do not need to install any postscript file converter application to work with this feature.

Steps to Convert XPS to PDF using Python

  1. Prepare the environment by configuring the Aspose.Page for converting XPS files
  2. Create an instance of the XpsDocument class to load the source file
  3. Initiate an object of the PdfSaveOptions class
  4. Create a memory stream to save the output PDF file
  5. Export the XPS file to PDF format using the PdfDevice class instance

These steps outline the workflow to convert XPS document to PDF in Python. Just load the source XPS document, create a memory stream, and render the output document to the stream. Finally, save that stream to a file path as per your requirements.

Code to Change XPS to PDF in Python

Use this sample code snippet to convert file from XPS to PDF in Python. Read the input XPS file into the instance of the XpsDocument class. Customize the desired properties using the PdfSaveOptions class, such as image compression, text compression, and file encryption according to your requirements. Next, render the generated PDF document using a stream which is then exported to the disk.

This guide has discussed the information relevant to the conversion of XPS to PDF in Python. Besides, if you are eager to explore EPS to PDF conversion, read the article on Convert EPS to PDF in Python.

 English