Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active June 28, 2022 09:20
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/26d821b928f8ca3cac014e4a5c80d714 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/26d821b928f8ca3cac014e4a5c80d714 to your computer and use it in GitHub Desktop.
Merge or Combine XPS Files Programmatically Java
// Initialize PDF output stream
FileOutputStream pdfStream = new FileOutputStream("MergeXPS.pdf");
// Load the first XPS document
XpsDocument document = new XpsDocument("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);
// Create an array of XPS files that will be merged with the first one
String[] filesToMerge = new String[] { "input2.xps", "input3.xps" };
// Merge XPS files to output PDF document
document.merge(filesToMerge, device, options);
// Initialize XPS output stream
FileOutputStream xpsStream = new FileOutputStream("mergedXPSfiles.xps");
// Load the first XPS document
XpsDocument document = new XpsDocument(dataDir + "input.xps");
// Create an array of XPS files that will be merged with the first one
var filesToMerge = new String[] { "input2.xps", "input3.xps" };
// Merge XPS files
document.merge(filesToMerge, xpsStream);
// Initialize PDF output stream
FileOutputStream pdfStream = new FileOutputStream("MergeXPS.pdf");
// Load the first XPS document
XpsDocument document = new XpsDocument("input.xps");
// Create rendering device for PDF format
PdfDevice device = new PdfDevice(pdfStream);
// Create an array of XPS files that will be merged with the first one
String[] filesToMerge = new String[] { "input2.xps", "input3.xps" };
// Merge XPS files to output PDF document
document.merge(filesToMerge, device, new PdfSaveOptions());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment