Convert XPS to PDF in Python

Aspose.Page for Python via .NET makes it easy to view, process, and convert XPS files to other widely used file formats which are highly compatible with almost all popular operating systems. Yes, we will convert XPS to PDF in Python-based project programmatically. Now, you will be able to develop an XPS to PDF converter to automate this file format conversion. Therefore, we highly recommend you opt for this Python library as it is super developer-friendly and offers easy-to-invoke methods. So, let’s go straight to the implementation of XPS file conversion.

The following points will be covered:

  1. XPS File Conversion - API Installation
  2. Convert XPS to PDF in Python - Code Sample
  3. Online XPS to PDF Converter

XPS File Conversion - API Installation

To install this Python library, you can download the latest version, or run the following pip command into terminal/CMD:

pip install aspose-page 
XPS File Conversion

Convert XPS to PDF in Python - Code Sample

We have the source XPS file to implement the feature.

Please follow the steps given below to turn XPS to PDF:

  • Initialize streams for input and output files.
  • Load the XPS document from the stream by creating an object of the XpsDocument class.
  • Create an instance of the PdfSaveOptions class.
  • Set the quality level of compression for an image by setting a value of jpeg_quality_level property.
  • text_compression property specifies the compression type to be used for all content streams except images.
  • Set the page_numbers property to set the array of numbers of pages to convert.
  • Create a rendering device for PDF format by creating an object of the PdfDevice class.
  • Call the save method to convert XPS to PDF.

Once you run the following code sample, it will convert XPS to PDF and save it onto the disk:

You can see the output of the above code sample in the image below:

Turn XPS to PDF

Online XPS to PDF Converter

Aspose.Page also offers an online tool to turn XPS to PDF robustly. Moreover, there are various options to upload the source file along with a simple drag-and-drop interface. Above all, you can place the URL of the cloud-hosted XPS file for the file format conversion.

Online XPS to PDF Converter

Turn XPS to PDF - Get a Free License

You can get a free temporary license to try this Python library without evaluation limitations.

Summing up

We are ending this blog post here. You can learn more about this XPS file conversion API by visiting documentation, API references, and the GitHub repository. So, we covered how to convert XPS to PDF in Python. In addition, we also give a slight touch to the online XPS to PDF converter. aspose.com will publish another blog post on any other interesting topic. Therefore, stay tuned for the regular updates.

Ask a question

You can let us know about your questions or queries on our forum.

Frequently Asked Questions – FAQs

How do I convert an XPS file to PDF?

You can automate XPS file conversion by installing Aspose.Page for Python via .NET. Moreover, please follow this link.

How do I open an .XPS file?

This online XPS Viewer is powered by Aspose.Page. It is web-based and you can view XPS files easily.

See Also