This tutorial provides details about how to convert XPS to PDF in Java. It covers the stepwise process, environment configuration information as well as a runnable code snippet to change XPS to PDF in Java. You only need to load the source XPS file and export it as a PDF file using a few API calls.
Steps to Convert XPS to PDF using Java
- Set up the system environment by installing Aspose.Page for converting XPS files
- Initialize a PDF output stream to create a PDF file
- Load the input XPS file with XpsDocument class
- Create an instance of the PdfSaveOptions class object to set PDF properties
- Convert the XPS file to PDF with the PdfDevice class object
These steps elaborate the procedure to convert XPS file to PDF in Java. Simply load the input XPS file, specify the required characteristics of the PDF file and export it to a file or a stream. The PdfSaveOptions class allows you to control the compression of images and text, as well as PDF encryption, page numbers, and other properties.
Code to Convert XPS to PDF in Java
This code snippet is efficient to convert XPS document to PDF in Java. The input file is loaded using the XpsDocument class and then you can set different properties exposed by the PdfSaveOptions class like outline tree height, outline tree expansion level, password, or encryption algorithm. After specifying the values for these options, create a PdfDevice and render the output PDF file.
This tutorial has covered the information related to the conversion of XPS file to PDF in Java. If you are interested to understand EPS to PNG image conversion, refer to the article on how to convert EPS to PNG in Java.