Merge XPS Files in Java

This basic tutorial explains how to merge XPS in Java. contains the step-by-step flow, in addition to a sample code to combine XPS files in Java. Additionally, you will also explore different options to customize the XPS merging process.

Steps to Merge XPS Files in Java

  1. Prepare the system by configuring the Aspose.Page to merge PostScript documents
  2. Initiate an object of XPSDocument class to load the input XPS document
  3. Initialize an instance of PdfSaveOptions class
  4. Create a PdfDevice class object for PDF format
  5. Specify the name of the XPS file to combine them
  6. Export the merged XPS files to the PDF format

These steps outline the process to combine XPS in Java. First of all, initiate a stream to load the input XPS file. Next, create an array of source XPS files and set custom options. Finally, export the merged output file to conclude the merging process.

Code to Combine XPS Files in Java

import com.aspose.page.*;
import com.aspose.xps.XpsDocument;
public class Main
{
public static void main(String[] args) throws Exception // Merge XPS files in Java
{
// Set the licenses
new License().setLicense("License.lic");
// Load the XPS file
XpsDocument document = new XpsDocument("input.xps");
// Create an array of XPS files
String[] filesForMerge = new String[] { "Output.xps", "Output.xps" };
// Initialize PdfSaveOptions class instance
com.aspose.xps.rendering.PdfSaveOptions options = new com.aspose.xps.rendering.PdfSaveOptions();
options.setJpegQualityLevel(100);
options.setImageCompression(com.aspose.xps.rendering.PdfImageCompression.Jpeg);
options.setTextCompression(com.aspose.xps.rendering.PdfTextCompression.Flate);
// Save the merged file
document.mergeToPdf(filesForMerge, "Merged-XPS.pdf", options);
System.out.println("XPS files merged successfully");
}
}

This bare-minimum code snippet demonstrates the feature to merge XPS to PDF in Java. However, you may enhance it to adjust the program depending on your needs. For instance, the number of source files, outline tree properties, page numbers, file encryption, etc. as per your requirements.

This guide has summarized how to merge XPS files in Java. Whereas, if you want to resize EPS files, refer to the article on Resize EPS in Java.

 English