Last active
October 23, 2025 21:10
-
-
Save aspose-com-gists/a92d54a3b6cd6e4cd5caabf8646db576 to your computer and use it in GitHub Desktop.
XPS to PDF Converter in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example; | |
| import java.io.IOException; | |
| import com.aspose.page.License; | |
| import com.aspose.xps.XpsDocument; | |
| public class main { | |
| public static void main(String[] args) throws IOException { | |
| try { | |
| // Define path for the working directory and load the Aspose.Page license. | |
| String dataDir = "data"; | |
| License lic = new License(); | |
| lic.setLicense(dataDir + "license.lic"); | |
| // Initialize an instance of the XpsDocument class with the source XPS file. | |
| XpsDocument document = new XpsDocument(dataDir + "input.xps"); | |
| // Create an object of the PdfSaveOptions class. | |
| com.aspose.xps.rendering.PdfSaveOptions options = new com.aspose.xps.rendering.PdfSaveOptions(); | |
| // Set the quality of the document by calling the setJpegQualityLevel method. | |
| options.setJpegQualityLevel(100); | |
| // Set the image and text compression and define the page numbers. | |
| options.setImageCompression(com.aspose.xps.rendering.PdfImageCompression.Jpeg); | |
| options.setTextCompression(com.aspose.xps.rendering.PdfTextCompression.Flate); | |
| options.setPageNumbers(new int[]{1, 2, 6}); | |
| // Call the saveAsPdf method to convert XPS to PDF. | |
| document.saveAsPdf(dataDir + "XPStoPDF_out.pdf", options); | |
| System.out.println("✅ Conversion successful!"); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment