Created
February 9, 2021 14:05
-
-
Save aspose-com-gists/36014fe18885c184d472ae34c0c29750 to your computer and use it in GitHub Desktop.
Convert OXPS or XPS to PDF Programmatically with Java
This file contains 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
// 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); |
This file contains 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
// 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