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:

  1. Initialise an XpsDocument with the primary XPS file, e.g., var document = new XpsDocument("first.xps");.
  2. Define a string array containing the paths of the additional XPS files to merge, for example:
    1string[] additionalXps = { "second.xps", "third.xps" };
  3. 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");
Example-MergeXPStoXPS.cs hosted with ❤ by GitHub

See XPS merge in Java and C++.

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:

  1. Initialise an XpsDocument with the primary XPS file, e.g., var document = new XpsDocument("first.xps");.
  2. Define a string array with the paths of the additional XPS files to merge, for example:
    1string[] additionalXps = { "second.xps", "third.xps" };
  3. Create a PdfSaveOptions instance and configure conversion options, e.g.:
    1var pdfSaveOptions = new PdfSaveOptions();
    2pdfSaveOptions.TextCompression = PdfTextCompression.Flate;
    3pdfSaveOptions.ImageCompression = PdfImageCompression.Auto;
    4pdfSaveOptions.JpegQualityLevel = 90;
  4. 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);
Example-MergeXPStoPDF.cs hosted with ❤ by GitHub

See XPS merge in Java and C++.

Let’s consider PdfSaveOptions. Using this class we can assign different conversion parameters while merging XPS files to PDF.

Evaluate XPS merging online on our XPS Merger.

You can download examples and data files from GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.