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:
- 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 in C#:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-.NET
2// The path to the documents directory.
3string dataDir = RunExamples.GetDataDir_WorkingWithDocumentMerging();
4// Load XPS document from XPS file
5XpsDocument document = new XpsDocument(dataDir + "input1.xps", new XpsLoadOptions());
6
7// Create an array of XPS files that will be merged with the first one
8string[] filesToMerge = new string[] { dataDir + "input2.xps", dataDir + "input3.xps" };
9
10// Merge XPS files to output XPS document
11document.Merge(filesToMerge, dataDir + "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:
- 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 C#:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-.NET
2// The path to the documents directory.
3string dataDir = RunExamples.GetDataDir_WorkingWithDocumentMerging();
4// Load XPS document form the XPS file
5XpsDocument document = new XpsDocument(dataDir + "input1.xps", new XpsLoadOptions());
6
7// Initialize options object with necessary parameters.
8Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions options = new Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions()
9{
10 JpegQualityLevel = 100,
11 ImageCompression = Aspose.Page.XPS.Presentation.Pdf.PdfImageCompression.Jpeg,
12 TextCompression = Aspose.Page.XPS.Presentation.Pdf.PdfTextCompression.Flate
13};
14
15// Create an array of XPS files that will be merged with the first one
16string[] filesToMerge = new string[] { dataDir + "input2.xps", dataDir + "input3.xps" };
17
18// Merge XPS files to output PDF file
19document.MergeToPdf(dataDir + "mergedXPSfiles.pdf", filesToMerge, 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.