Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active June 28, 2022 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/7f6563854a9626c9de9c7ad84431df43 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/7f6563854a9626c9de9c7ad84431df43 to your computer and use it in GitHub Desktop.
Merge or Combine XPS Files Programmatically in C# .NET
// Initialize PDF output stream
using (Stream pdfStream = File.Open("mergedXPSfiles.pdf", FileMode.Create, FileAccess.Write))
// Initialize XPS input stream
using (Stream xpsStream = File.Open("input.xps", FileMode.Open, FileAccess.Read))
{
// Load the first XPS document from the stream
XpsDocument document = new XpsDocument(xpsStream, new XpsLoadOptions());
// Initialize options object with necessary parameters.
PdfSaveOptions options = new PdfSaveOptions()
{
JpegQualityLevel = 100,
ImageCompression = Aspose.Page.XPS.Presentation.Pdf.PdfImageCompression.Jpeg,
TextCompression = Aspose.Page.XPS.Presentation.Pdf.PdfTextCompression.Flate
};
// Create rendering device for PDF format
PdfDevice device = new PdfDevice(pdfStream);
// Create an array of XPS files that will be merged with the first one
string[] filesToMerge = new string[] { "input2.xps", "input3.xps" };
// Merge XPS files to output PDF document
document.Merge(filesToMerge, device, options);
}
// Initialize XPS output stream
using (System.IO.Stream outStream = System.IO.File.Open("mergedXPSfiles.xps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
// Load XPS document
XpsDocument document = new XpsDocument("input.xps", new XpsLoadOptions());
// Create an array of XPS files that will be merged with the first one
string[] filesToMerge = new string[] { "input2.xps", "input3.xps" };
// Merge XPS files to output XPS document
document.Merge(filesToMerge, outStream);
}
// Initialize PDF output stream
using (Stream pdfStream = File.Open("mergedXPSfiles.pdf", FileMode.Create, FileAccess.Write))
// Initialize XPS input stream
using (Stream xpsStream = File.Open("input.xps", FileMode.Open, FileAccess.Read))
{
// Load the first XPS document from the stream
XpsDocument document = new XpsDocument(xpsStream, new XpsLoadOptions());
// Create rendering device for PDF format
PdfDevice device = new PdfDevice(pdfStream);
// Create an array of XPS files that will be merged with the first one
string[] filesToMerge = new string[] { "input2.xps", "input3.xps" };
// Merge XPS files to output PDF document
document.Merge(filesToMerge, device, new PdfSaveOptions());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment