Merge XPS files | Aspose.Page for C++
You can check the quality of Aspose.Page XPS merging and view the results via free online XPS Merger
Aspose.Page C++ XPS merger allows to merge XPS files to XPS document on Windows and Linux.
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 (by Merge) XPS files with created document and save it.
Following code snippet shows how to merge XPS files in C++:
1 // The path to the documents directory.
2 System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentMerging();
3
4 // Load XPS document from XPS file
5 System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(dataDir + u"input.xps", System::MakeObject<XpsLoadOptions>());
6
7 // Create an array of XPS files that will be merged with the first one
8 System::ArrayPtr<System::String> filesToMerge = System::MakeArray<System::String>({dataDir + u"Demo.xps", dataDir + u"sample.xps"});
9
10 // Merge XPS files to output XPS document
11 document->Merge(filesToMerge, dataDir + u"mergedXPSfiles.xps");
Aspose.Page C++ XPS merger allows also to merge XPS files into PDF document on Windows and Linux.
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 (by MergeToPdf) 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-C
2 // The path to the documents directory.
3 System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentMerging();
4
5 // Load XPS document form the XPS file
6 System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(dataDir + u"input.xps", System::MakeObject<XpsLoadOptions>());
7
8 // Initialize options object with necessary parameters.
9 System::SharedPtr<Aspose::Page::XPS::Presentation::Pdf::PdfSaveOptions> options = System::MakeObject<Aspose::Page::XPS::Presentation::Pdf::PdfSaveOptions>();
10 options->set_JpegQualityLevel(100);
11 options->set_ImageCompression(Aspose::Page::XPS::Presentation::Pdf::PdfImageCompression::Jpeg);
12 options->set_TextCompression(Aspose::Page::XPS::Presentation::Pdf::PdfTextCompression::Flate);
13
14 // Create an array of XPS files that will be merged with the first one
15 System::ArrayPtr<System::String> filesToMerge = System::MakeArray<System::String>({dataDir + u"Demo.xps", dataDir + u"sample.xps"});
16
17 // Merge XPS files to output PDF file
18 document->MergeToPdf(filesToMerge, dataDir + u"mergedXPSfiles.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.
Evaluate XPS merging online on our XPS Merger.
You can download examples and data files from GitHub.