Merge XPS files | Aspose.Page for Java
You can check the quality of Aspose.Page XPS Merger and view the results via free online XPS Merger
Aspose.Page Java XPS merger allows to merge XPS files to XPS document on any OS for which Java Virtual Machine exists.
It is necessary to do several steps in order to perform XPS merge:
- Create an instance of XpsDocument from the first XPS file.
- Create an array of XPS files that will be merged with the first one.
- Merge XPS files with created document and save it.
Following code snippet shows how to merge XPS files to PDF document in Java:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
2// The path to the documents directory.
3String dataDir = Utils.getDataDir();
4// Load the first XPS file in a document
5XpsDocument document = new XpsDocument(dataDir + "input.xps");
6
7// Create an array of XPS files that will be merged with the first one
8String[] filesForMerge = new String[] { dataDir + "Demo.xps", dataDir + "sample.xps" };
9
10//merge and save to output XPS file
11document.merge(filesForMerge, dataDir + "mergedXPSfiles.xps");
Aspose.Page Java XPS merger allows also to merge XPS files to PDF document.
It is necessary to do several steps in order to perform XPS to PDF merge:
- Create an instance of XpsDocument from the first XPS file.
- Create an array of XPS files that will be merged with the first one.
- Specify TextCompression, ImageCompression, JpegQualityLevel, and other options of PdfSaveOptions.
- Merge XPS files with created document and save it as PDF with PDF save options.
Following code snippet shows how to merge XPS files to PDF document in Java:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
2// The path to the documents directory.
3String dataDir = Utils.getDataDir();
4
5// Load the first XPS file in a document
6XpsDocument document = new XpsDocument(dataDir + "input.xps");
7
8// Create an array of XPS files that will be merged with the first one
9String[] filesForMerge = new String[] { dataDir + "Demo.xps", dataDir + "sample.xps" };
10
11// Initialize options object with necessary parameters.
12com.aspose.xps.rendering.PdfSaveOptions options = new com.aspose.xps.rendering.PdfSaveOptions();
13options.setJpegQualityLevel(100);
14options.setImageCompression(com.aspose.xps.rendering.PdfImageCompression.Jpeg);
15options.setTextCompression(com.aspose.xps.rendering.PdfTextCompression.Flate);
16options.setPageNumbers(new int[] { 1, 2, 6 });
17
18document.mergeToPdf(filesForMerge, dataDir + "XPStoPDF.pdf", options);
Let’s consider
PdfSaveOptions. Using this class we can assign different conversion parameters while merging XPS to PDF.
- JpegQualityLevel controls a quality of images in PDF document if ImageCompression algorithm is JPEG and can be from 0 to 100.
- ImageCompression algorithm encapsulated in PdfImageCompression Enumeration, may be Run Length Encoding (RLE), Flate, Lempel-Ziv-Welch (LZW) with base or optimized pedictor, JPEG , none (raw image bytes) and auto (the most appropriate compression for each image). Default is auto compression.
- TextCompression algorithm encapsulated in PdfTextCompression Enumeration, may be Run Length Encoding (RLE), Flate, Lempel-Ziv-Welch (LZW) and none. Default value in XPS to PDF merging is Flate.
- EncryptionDetails encapsulated in PdfEncryptionDetails. It allows setting encryption algorithm, permisions, owner and user passwords for PDF document.
- OutlineTreeExpansionLevel and OutlineTreeHeight controls view of document outline.