XPS ファイルの結合 | Aspose.Page for Python via .NET
Aspose.Page XPS Merger の品質を確認し、結果を確認するには、無料のオンラインツール XPS Merger をご利用ください。
XPS マージを実行するには、以下の手順に従ってください。
- 最初の入力 XPS ドキュメント用の入力ストリームを初期化します。
- 出力 XPS ドキュメント用の出力ストリームを初期化します。
- 最初の XPS ファイルとマージする XPS ファイルの配列を作成します。
- 先ほど作成した入力ストリームから XpsDocument のインスタンスを作成します。
- 作成したドキュメントと 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)
Aspose.Page Python XPS 結合ツールを使用すると、XPS ファイルを PDF ドキュメントに結合することもできます。
XPS から PDF への結合を実行するには、いくつかの手順を実行する必要があります。
- 最初の入力 XPS ドキュメント用の入力ストリームを初期化します。
- 出力 PDF ドキュメント用の出力ストリームを初期化します。
- 最初のファイルと結合する XPS ファイルの配列を作成します。
- 先ほど作成した入力ストリームから XpsDocument のインスタンスを作成します。
- PdfSaveOptions の TextCompression、ImageCompression、JpegQualityLevel などのオプションを指定します。
- 先ほど作成した出力ストリームから PdfDevice のインスタンスを作成します。
- 作成したドキュメントに 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)
PdfSaveOptions について考えてみましょう。このクラスを使用すると、XPS を PDF に結合する際にさまざまな変換パラメータを指定できます。
- JpegQualityLevel は、ImageCompression アルゴリズムが JPEG に設定されている場合に、PDF ドキュメント内の画像品質を制御します。値の範囲は 0 から 100 です。
- ImageCompression アルゴリズムは PdfImageCompression 列挙体にカプセル化されており、ランレングス符号化 (RLE)、Flate、Lempel-Ziv-Welch (LZW) (ベースまたは最適化された予測子を使用)、JPEG、なし (生の画像バイト)、自動 (各画像に最適な圧縮) などのオプションが提供されます。デフォルト設定は自動圧縮です。
- TextCompression アルゴリズムは PdfTextCompression 列挙体にカプセル化されており、ランレングス符号化 (RLE)、Flate、Lempel-Ziv-Welch (LZW)、なしなどのオプションが提供されます。 XPSからPDFへの結合時のデフォルト値はFlateです。
- EncryptionDetails は PdfEncryptionDetails にカプセル化されています。これにより、PDFドキュメントの暗号化アルゴリズム、権限、所有者、およびユーザーパスワードを設定できます。
- OutlineTreeExpansionLevel および OutlineTreeHeight パラメーターは、ドキュメントのアウトラインの表示を制御します。