Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created February 9, 2021 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
// Initialize PDF output stream
FileOutputStream pdfStream = new FileOutputStream(dataDir + "OXPStoPDF.pdf");
// 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 });
// Create rendering device for PDF format
PdfDevice device = new PdfDevice(pdfStream);
// Save output PDF file
document.save(device, options);
// Initialize PDF output stream
FileOutputStream pdfStream = new FileOutputStream(dataDir + "XPStoPDF.pdf");
// 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);
// Create rendering device for PDF format
PdfDevice device = new PdfDevice(pdfStream);
// Save output PDF file
document.save(device, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment