Convert XPS OXPS to PDF Java

XPS is a fixed-document format often used to organize information for printing purposes. Likewise, OXPS files are also based on XML paper Specifications. You can easily convert XPS or OXPS files to PDF documents programmatically using Java language. Let us check out the following sections related to XPS and OXPS files conversion:

XPS or OXPS to PDF Conversion – API Installation

Aspose.Page for Java API is designed to create, edit, manipulate and convert different fixed document formats including XPS, OXPS, EPS, PS, etc. You can quickly configure the API by downloading the JAR file from the Downloads section or adding the below configuration in the pom.xml file of your Maven project. This will configure the API hosted on Aspose Artifactory:

Repository:

 <repositories>
     <repository>
         <id>snapshots</id>
         <name>repo</name>
         <url>http://repository.aspose.com/repo/</url>
     </repository>

</repositories>

Dependency:

 <dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-page</artifactId>
        <version>20.1</version>
    </dependency>
</dependencies>

Convert XPS to PDF Programmatically using Java

You can convert XPS files to PDF documents with high fidelity among the input and output files. You need to follow the steps below for the conversion:

The following code snippet shows how to convert XPS to PDF programmatically using Java:

Convert OXPS to PDF Programmatically in Java

OXPS is a fixed layout format that can be used for creating letters, memos, and other official documents. Moreover, OXPS to PDF conversion is quite similar with above use case. So far we have learned how to convert all pages in the input file to PDF. Let us proceed another step further where we will be converting specific pages of OXPS file to PDF document. You can easily convert OXPS file to PDF in your Java applications. Below are the steps for converting OXPS to PDF document:

  • Load input OXPS document
  • Initialize PdfSaveOptions object with necessary parameters
  • Specify the page numbers with setPageNumbers method
  • Create rendering device for PDF format
  • Save output PDF file

The code below explains how to convert OXPS to PDF programmatically in Java:

As we have discussed above, this code will convert specific pages to PDF. The output PDF file will comprise of first and third page from the input OXPS file.

Conclusion

In this article, we have explored how to convert XPS or OXPS files to PDF documents. We have explored how to convert a whole document with all pages, as well as converting a few pages to PDF format files. Moreover, the API supports several other file formats that you can create, edit, or manipulate as per your requirements. We hope you must be interested to learn more, several other learning resources include API documentation as well as the Examples project. Furthermore, you can discuss any of your requirements or concerns via the Free Support Forum. We positively look forward to assisting you!

See Also