合并 XPS 文件 | .NET API 解决方案

您可以通过免费在线工具 XPS Merger

检查 Aspose.Page XPS 合并的质量并查看结果。

Aspose.Page .NET XPS Merge 允许使用 .NET 平台支持的任何语言(例如 C#、VB 和 J#)将 XPS 文件合并为 XPS 文档。
执行 XPS 合并需要执行以下几个步骤:

  1. 使用主 XPS 文件初始化一个 XpsDocument,例如 var document = new XpsDocument("first.xps");
  2. 定义一个字符串数组,其中包含要合并的附加 XPS 文件的路径,例如:
1string[] additionalXps = { "second.xps", "third.xps" };
  1. 将每个附加 XPS 添加到文档中(例如 foreach (var file in additionalXps) document.AddPage(file);),然后保存合并后的 XPS:
1document.Save("merged.xps");


以下代码片段展示了如何在 C# 中合并 XPS 文件:

 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

请参阅 JavaC++ 中的 XPS 合并。

Aspose.Page .NET XPS 合并还允许将 XPS 文件合并为 PDF 文档。
执行 XPS 到 PDF 合并需要执行以下几个步骤:

  1. 使用主 XPS 文件初始化一个 XpsDocument,例如 var document = new XpsDocument("first.xps");
  2. 定义一个字符串数组,其中包含要合并的附加 XPS 文件的路径,例如:
1string[] additionalXps = { "second.xps", "third.xps" };
  1. 创建一个 PdfSaveOptions 实例并配置转换选项,例如:
1var pdfSaveOptions = new PdfSaveOptions();
2pdfSaveOptions.TextCompression = PdfTextCompression.Flate;
3pdfSaveOptions.ImageCompression = PdfImageCompression.Auto;
4pdfSaveOptions.JpegQualityLevel = 90;
  1. 将每个附加的 XPS 添加到文档中(例如,foreach (var file in additionalXps) document.AddPage(file);)并将结果保存为 PDF:
1document.Save("merged.pdf", pdfSaveOptions);


以下代码片段展示了如何在 C# 中将 XPS 文件合并为 PDF 文档:

 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);

请参阅 JavaC++ 中的 XPS 合并。

我们来看一下 PdfSaveOptions。使用这个类,我们可以在将 XPS 文件合并为 PDF 时指定不同的转换参数。

在我们的 XPS 合并器 上在线评估 XPS 合并。

您可以从 GitHub 下载示例和数据文件。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.