XPS ファイルの結合 | .NET 経由の Python 用 Aspose.Page

Aspose.Page XPS Merger の品質を確認し、結果を確認するには、無料のオンラインツール 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
 3from aspose.page.xps import *
 4from aspose.page.xps.presentation.pdf import *
 5from util import Util
 6###############################################
 7###### Class and Method declaration here ######
 8###############################################
 9
10# The path to the documents directory.
11data_dir = Util.get_data_dir_working_with_document_merging()
12# Initialize the PDF output stream
13with open(data_dir + "mergedXPSfiles.pdf", "wb") as pdf_stream:
14    # Initialize an XPS input stream
15    with open(data_dir + "input.xps", "rb") as xps_stream:
16        # Load the XPS document form the stream
17        document = XpsDocument(xps_stream, XpsLoadOptions())
18        # or load the XPS document directly from a file. No xpsStream is needed then.
19        # XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions());
20        
21        # Initialize an options object with necessary parameters.
22        options = PdfSaveOptions()
23        
24        options.jpeg_quality_level = 100
25        options.image_compression = PdfImageCompression.JPEG
26        options.text_compression = PdfTextCompression.FLATE
27        
28        # Create a rendering device for PDF format
29        device = PdfDevice(pdf_stream)
30        
31        # Create an array of XPS files that will be merged with the first one
32        files_to_merge = [ data_dir + "Demo.xps", data_dir + "sample.xps" ]
33        
34        # Merge XPS files to output PDF document
35        document.merge(files_to_merge, device, options)

XPS 結合については、 .NETJavaC++ をご覧ください。

Aspose.Page Python XPS 結合ツールを使用すると、XPS ファイルを PDF ドキュメントに結合することもできます。

XPS から PDF への結合を実行するには、いくつかの手順を実行する必要があります。

  1. 最初の入力 XPS ドキュメント用の入力ストリームを初期化します。
  2. 出力 PDF ドキュメント用の出力ストリームを初期化します。
  3. 最初のファイルと結合する 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
 3from aspose.page.xps import *
 4from util import Util
 5###############################################
 6######## Class and Method declaration #########
 7###############################################
 8
 9# The path to the documents directory.
10data_dir = Util.get_data_dir_working_with_document_merging()
11# Initialize an XPS output stream
12with open(data_dir + "mergedXPSfiles.xps", "wb") as out_stream:
13    # Initialize the XPS input stream
14    with open(data_dir + "input.xps", "rb") as in_stream:
15        # Load the XPS document from the stream
16        document = XpsDocument(in_stream, XpsLoadOptions())
17        # or load the 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        files_to_merge = [ data_dir + "Demo.xps", data_dir + "sample.xps" ]
22        
23        # Merge XPS files to the output PDF document
24        document.merge(files_to_merge, out_stream)

XPS 結合については、 .NETJavaC++ をご覧ください。

PdfSaveOptions について考えてみましょう。このクラスを使用すると、XPS を PDF に結合する際にさまざまな変換パラメータを指定できます。

XPS Megar で、XPS マージ機能をオンラインで評価できます。

サンプルとデータファイルは GitHub からダウンロードできます。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.