C++ を使用して PostScript ファイルを PDF に結合

Aspose.Page PS マージの品質を確認し、無料のオンライン PostScipt Merger で結果を表示できます。

Aspose.Page for C++ の PS マージ機能を使用すると、Windows および Linux 上で PostScript (PS) ファイルを PDF ドキュメントにマージできます。
PS ファイルを PDF にマージするには、いくつかの手順を実行する必要があります。

  1. 最初の PostScript ファイルから PsDocument のインスタンスを作成します。
  2. 最初のファイルとマージする PS ファイルの配列を作成します。
  3. PdfSaveOptions を使用して、AdditionalFontsFolder と SuppressError のブール値を指定します。
  4. 作成したドキュメントにPSファイルを結合( MergeToPdfを使用)し、PDF保存オプションを使用してPDFとして保存します。
  5. SuppressErrors値がtrue(デフォルト)の場合、PostScriptファイルとPDFドキュメントの結合中に発生したエラーを確認し、Exceptionsリストに保存できます。


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

 1    // The path to the documents directory.
 2    System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentMerging();
 3    
 4    // Initialize PS document with the first PostScript file
 5    System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(dataDir + u"input.ps");
 6    
 7    // Create an array of PostScript files that will be merged with the first one
 8    System::ArrayPtr<System::String> filesForMerge = System::MakeArray<System::String>({dataDir + u"input2.ps", dataDir + u"input3.ps"});
 9    
10    // If you want to convert Postscript file despite of minor errors set this flag
11    bool suppressErrors = true;
12    
13    //Initialize options object with necessary parameters.
14    System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(suppressErrors);
15    // If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
16    options->set_AdditionalFontsFolders(System::MakeArray<System::String>({u"{FONT_FOLDER}"}));
17    
18    // Default page size is 595x842 and it is not mandatory to set it in SaveOptions
19    // But if you need to specify the page size following line
20    //PdfSaveOptions options = new PdfSaveOptions(suppressErrors, new Aspose.Page.Drawing.Size(595, 842));
21    
22    document->MergeToPdf(dataDir + u"outputPDF_out.pdf", filesForMerge, options);
23    
24    //Review errors
25    if (suppressErrors)
26    {
27        for (auto&& ex : System::IterateOver(options->get_Exceptions()))
28        {
29            System::Console::WriteLine(ex->get_Message());
30        }
31    }

.NET および Java の PS マージを参照してください。

PdfSaveOptions について考えてみましょう。このクラスを使用すると、PS から PDF へのマージ時にさまざまな変換パラメータを指定できます。

PS Merger で PS マージ機能をオンラインで評価できます。

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