合并 XPS 文件 | 通过 .NET 为 Python 编写的 Aspose.Page

您可以通过免费在线 XPS Merger

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


要执行 XPS 合并,请按照以下步骤操作:

  1. 为第一个输入 XPS 文档初始化输入流
  2. 为输出 XPS 文档初始化输出流
  3. 创建一个将与第一个 XPS 文件合并的 XPS 文件数组
  4. 从先前创建的输入流创建 XpsDocument 实例
  5. 将 XPS 文件与创建的文档合并并保存


以下示例代码片段演示了如何使用 Python 将 XPS 文件合并为 PDF 文档:

 1# For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Python
 2# The path to the documents directory.
 3data_dir = Util.get_data_dir_working_with_document_merging()
 4# Initialize the PDF output stream
 5with open(data_dir + "mergedXPSfiles.pdf", "wb") as pdf_stream:
 6    # Initialize an XPS input stream
 7    with open(data_dir + "input.xps", "rb") as xps_stream:
 8        # Load the XPS document form the stream
 9        document = XpsDocument(xps_stream, XpsLoadOptions())
10        # or load the XPS document directly from a file. No xpsStream is needed then.
11        # XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions());
12        
13        # Initialize an options object with necessary parameters.
14        options = PdfSaveOptions()
15        
16        options.jpeg_quality_level = 100
17        options.image_compression = PdfImageCompression.JPEG
18        options.text_compression = PdfTextCompression.FLATE
19        
20        # Create a rendering device for PDF format
21        device = PdfDevice(pdf_stream)
22        
23        # Create an array of XPS files that will be merged with the first one
24        files_to_merge = [ data_dir + "Demo.xps", data_dir + "sample.xps" ]
25        
26        # Merge XPS files to output PDF document
27        document.merge(files_to_merge, device, options)

请参阅 .NETJavaC++ 中的 XPS 合并。

Aspose.Page Python XPS 合并器还允许将 XPS 文件合并为 PDF 文档。

执行 XPS 到 PDF 合并需要执行以下几个步骤:

  1. 为第一个输入 XPS 文档初始化输入流。
  2. 为输出 PDF 文档初始化输出流。
  3. 创建一个将与第一个 XPS 文件合并的 XPS 文件数组。
  4. 从先前创建的输入流创建 XpsDocument 的实例。
  5. 指定 PdfSaveOptionsTextCompressionImageCompressionJpegQualityLevel 和其他选项。
  6. 从之前创建的输出流创建 PdfDevice 的实例。
  7. 将 XPS 文件合并到创建的文档中,并使用 PDF 保存选项将其保存为 PDF。


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

 1# For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Python
 2
 3# The path to the documents directory.
 4data_dir = Util.get_data_dir_working_with_document_merging()
 5# Initialize an XPS output stream
 6with open(data_dir + "mergedXPSfiles.xps", "wb") as out_stream:
 7    # Initialize the XPS input stream
 8    with open(data_dir + "input.xps", "rb") as in_stream:
 9        # Load the XPS document from the stream
10        document = XpsDocument(in_stream, XpsLoadOptions())
11        # or load the XPS document directly from file. No xpsStream is needed then.
12        # XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions());
13        
14        # Create an array of XPS files that will be merged with the first one
15        files_to_merge = [ data_dir + "Demo.xps", data_dir + "sample.xps" ]
16        
17        # Merge XPS files to the output PDF document
18        document.merge(files_to_merge, out_stream)

请参阅 .NETJavaC++ 中的 XPS 合并。

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

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

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

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.