Python を使って PostScript ファイルを PDF に結合

Aspose.Page PS Merger の品質を確認し、結果を確認するには、無料のオンラインツール PostScipt Merger をご利用ください。


Python を使用して複数の PS ファイルを 1 つの PDF に結合するには、次の簡単な手順に従います。

  1. 最初の入力 PS ファイルの入力ストリームを初期化します。
  2. 出力 PDF ドキュメントの出力ストリームを初期化します。
  3. 最初のファイルと結合する PS ファイルの配列を作成します。
  4. 作成した入力ストリームから PsDocument のインスタンスを作成します。
  5. PdfSaveOptions を使用して、AdditionalFontsFolder と SuppressError のブール値を指定します。
  6. 先ほど作成した出力ストリームから PdfDevice のインスタンスを作成します。
  7. 作成したドキュメントと PostScript ファイルを結合し、PDF 保存オプションを使用して PDF として保存します。


次のコード スニペットは、Python で PS ファイルを PDF ドキュメントに結合する方法を示しています。

 1# For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Python
 2
 3from aspose.page.eps import *
 4from aspose.page.eps.device 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 PDF output stream
13pdf_stream = open(data_dir + "outputPDF_out.pdf", "wb")
14# Initialize the first PostScript file input stream
15ps_stream = open(data_dir + "input.ps", "rb",)
16document = PsDocument(ps_stream)
17
18# Create an array of PostScript files that will be merged with the first one
19files_for_merge = [ data_dir + "input2.ps", data_dir + "input3.ps" ]
20
21# If you want to convert Postscript file despite of minor errors set this flag
22suppress_errors = True
23
24#Initialize options object with necessary parameters.
25options = PdfSaveOptions(suppress_errors)
26# If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
27options.additional_fonts_folders = [ """{FONT_FOLDER}""" ]
28
29# Default page size is 595x842 and it is not mandatory to set it in PdfDevice
30device = PdfDevice(pdf_stream)
31# But if you need to specify size and image format use following line
32#Aspose.Page.EPS.Device.PdfDevice device = new Aspose.Page.EPS.Device.PdfDevice(pdfStream, new aspose.pydrawing.Size(595, 842));
33
34try:
35    document.merge(files_for_merge, device, options)
36finally:
37    ps_stream.close()
38    pdf_stream.close()

PS結合については、 .NET、 Java、 C++をご覧ください。

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

PS Merger で PS マージ機能をオンラインで評価してください。

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