Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active July 4, 2024 13:27
Show Gist options
  • Save aspose-com-gists/36014fe18885c184d472ae34c0c29750 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/36014fe18885c184d472ae34c0c29750 to your computer and use it in GitHub Desktop.
Convert OXPS or XPS to PDF Programmatically with Java
// Load input OXPS document
XpsDocument document = new XpsDocument(dataDir + "input.oxps");
// Initialize options object with necessary parameters
PdfSaveOptions options = new PdfSaveOptions();
// Specify page numbers to render
options.setPageNumbers(new int[] { 1,3 });
// Save OXPS document to output PDF file
document.saveAsPdf(dataDir + "OXPStoPDF.pdf", options);
// Load input XPS document
XpsDocument document = new XpsDocument(dataDir + "input.xps");
// Initialize options object with necessary parameters
PdfSaveOptions options = new PdfSaveOptions();
options.setJpegQualityLevel(100);
options.setImageCompression(PdfImageCompression.Jpeg);
options.setTextCompression(PdfTextCompression.Flate);
// Save XPS document to output PDF file
document.saveAsPdf(dataDir + "XPStoPDF.pdf", options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment