Merge XPS files | .NET API Solution
You can check the quality of Aspose.Page XPS merger and view the results via free online XPS Merger
Aspose.Page .NET XPS Merge allows to merge XPS files to XPS document with using of any language supported by .NET platform: C#, VB, J#.
It is necessary to do several steps in order to perform XPS merge:
- Initialise an
XpsDocumentwith the primary XPS file, e.g.,var document = new XpsDocument("first.xps");. - Define a string array containing the paths of the additional XPS files to merge, for example:
1string[] additionalXps = { "second.xps", "third.xps" }; - Add each additional XPS to the document (e.g.,
foreach (var file in additionalXps) document.AddPage(file);) and then save the merged XPS:1document.Save("merged.xps");
The following code snippet shows how to merge XPS files in C#:
1// Merge several XPS files to one XPS document.
2
3// Load XPS document from XPS file
4XpsDocument document = new XpsDocument(DataDir + "input.xps", new XpsLoadOptions());
5
6// Create an array of XPS files that will be merged with the first one
7string[] filesToMerge = new string[] { DataDir + "Demo.xps", DataDir + "sample.xps" };
8
9// Merge XPS files to output XPS document
10document.Merge(filesToMerge, OutputDir + "mergedXPSfiles.xps");Aspose.Page .NET XPS Merge also allows to merge XPS files to PDF document.
It is necessary to do several steps in order to perform XPS to PDF merge:
- Initialise an
XpsDocumentwith the primary XPS file, e.g.,var document = new XpsDocument("first.xps");. - Define a string array with the paths of the additional XPS files to merge, for example:
1string[] additionalXps = { "second.xps", "third.xps" }; - Create a
PdfSaveOptionsinstance and configure conversion options, e.g.:1var pdfSaveOptions = new PdfSaveOptions(); 2pdfSaveOptions.TextCompression = PdfTextCompression.Flate; 3pdfSaveOptions.ImageCompression = PdfImageCompression.Auto; 4pdfSaveOptions.JpegQualityLevel = 90; - Add each additional XPS to the document (e.g.,
foreach (var file in additionalXps) document.AddPage(file);) and save the result as PDF:1document.Save("merged.pdf", pdfSaveOptions);
The following code snippet shows how to merge XPS files to PDF document in C#:
1// Merge several XPS files to one PDF document.
2
3// Load XPS document from the XPS file
4XpsDocument document = new XpsDocument(DataDir + "input.xps", new XpsLoadOptions());
5
6// Initialize options object with necessary parameters.
7Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions options = new Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions()
8{
9 JpegQualityLevel = 100,
10 ImageCompression = Aspose.Page.XPS.Presentation.Pdf.PdfImageCompression.Jpeg,
11 TextCompression = Aspose.Page.XPS.Presentation.Pdf.PdfTextCompression.Flate
12};
13
14// Create an array of XPS files that will be merged with the first one
15string[] filesToMerge = new string[] { DataDir + "Demo.xps", DataDir + "sample.xps" };
16
17// Merge XPS files to output PDF file
18document.MergeToPdf(filesToMerge, OutputDir + "mergedXPSfiles.pdf", options);Let’s consider
PdfSaveOptions. Using this class we can assign different conversion parameters while merging XPS files 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.
Evaluate XPS merging online on our XPS Merger.
You can download examples and data files from GitHub.