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:

  1. Initialize an output stream for output XPS document.
  2. Initialize an input stream for the first input XPS document.
  3. Create an array of XPS files that will be merged with the first one.
  4. Create an instance of XpsDocument from created earlier input stream.
  5. 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-C
 2// Output stream
 3System::SharedPtr<System::IO::Stream> outStream = System::IO::File::Open(RunExamples::outDir() + u"mergedXPSfiles.xps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
 4// Clearing resources under 'using' statement
 5System::Details::DisposeGuard<1> __dispose_guard_1({ outStream });
 6// ------------------------------------------
 7try {
 8	System::SharedPtr<System::IO::Stream> inStream = System::IO::File::Open(RunExamples::dataDir() + u"input.xps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
 9	// Clearing resources under 'using' statement
10	System::Details::DisposeGuard<1> __dispose_guard_0({ inStream });
11	// ------------------------------------------
12
13	try
14	{
15		// Load XPS document form the stream
16		System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(xpsStream, System::MakeObject<XpsLoadOptions>());
17		// or load XPS document directly from file. No xpsStream is needed then.
18		// XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions());
19
20		// Create an array of XPS files that will be merged with the first one
21		System::ArrayPtr<System::String> filesForMerge = System::MakeArray<System::String>({dataDir() + u"input2.xps", dataDir() + u"input3.xps"});
22
23		document->Merge(filesForMerge, outStream);
24	}
25	catch (...)
26	{
27		__dispose_guard_0.SetCurrentException(std::current_exception());
28	}
29}
30catch (...)
31{
32	__dispose_guard_1.SetCurrentException(std::current_exception());
33}

See XPS merge in .Net and Java.

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:

  1. Initialize an output stream for output PDF document.
  2. Initialize an input stream for the first input XPS document.
  3. Create an array of XPS files that will be merged with the first one.
  4. Create an instance of XpsDocument from created earlier input stream.
  5. Specify TextCompressionImageCompressionJpegQualityLevel, and other options of PdfSaveOptions.
  6. Create an instance of PdfDevice from created earlier output stream.
  7. 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-C
 2// Input file
 3System::SharedPtr<System::IO::Stream> pdfStream = System::IO::File::Open(RunExamples::outDir() + u"XPStoPDF.pdf", System::IO::FileMode::Create, System::IO::FileAccess::Write);
 4// Clearing resources under 'using' statement
 5System::Details::DisposeGuard<1> __dispose_guard_1({ pdfStream });
 6// ------------------------------------------
 7try {
 8	System::SharedPtr<System::IO::Stream> xpsStream = System::IO::File::Open(RunExamples::dataDir() + u"input.xps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
 9	// Clearing resources under 'using' statement
10	System::Details::DisposeGuard<1> __dispose_guard_0({ xpsStream });
11	// ------------------------------------------
12
13	try
14	{
15		// Load XPS document form the stream
16		System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(xpsStream, System::MakeObject<XpsLoadOptions>());
17		// or load XPS document directly from file. No xpsStream is needed then.
18		// XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions());
19
20		// Initialize options object with necessary parameters.
21		System::SharedPtr<Aspose::Page::Xps::Presentation::Pdf::PdfSaveOptions> options = [&] { auto tmp_0 = System::MakeObject<Aspose::Page::Xps::Presentation::Pdf::PdfSaveOptions>(); tmp_0->set_JpegQualityLevel(100); tmp_0->set_ImageCompression(Aspose::Page::Xps::Presentation::Pdf::PdfImageCompression::Jpeg); tmp_0->set_TextCompression(Aspose::Page::Xps::Presentation::Pdf::PdfTextCompression::Flate); tmp_0->set_PageNumbers(System::MakeArray<int32_t>({ 1, 2, 6 })); return tmp_0; }();
22
23		// Create rendering device for PDF format
24		System::SharedPtr<Aspose::Page::Xps::Presentation::Pdf::PdfDevice> device = System::MakeObject<Aspose::Page::Xps::Presentation::Pdf::PdfDevice>(pdfStream);
25
26		// Create an array of XPS files that will be merged with the first one
27		System::ArrayPtr<System::String> filesForMerge = System::MakeArray<System::String>({dataDir() + u"input2.xps", dataDir() + u"input3.xps"});
28
29		document->Merge(filesForMerge, device, options);
30	}
31	catch (...)
32	{
33		__dispose_guard_0.SetCurrentException(std::current_exception());
34	}
35}
36catch (...)
37{
38	__dispose_guard_1.SetCurrentException(std::current_exception());
39}

See XPS merge in .Net and Java.

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

Evaluate XPS merging online on our XPS Merger.

You can download examples and data files from GitHub.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.