PS ドキュメントを PDF にマージ

複数の PostScript ファイルを結合する C++ API ソリューション

 

PostScript ファイル形式には複数のページを含めることができますが、XPS 形式のように複数のファイルを 1 つのドキュメントに結合する機能はありません。 C++ 用の Aspose.Page API ソリューションは、複数の PS または EPS ファイルを 1 つの PDF ドキュメントにマージする機能を提供します。

次のコード例は、C++ を使用して PostScript ファイルをマージする方法を示しています。この機能を Web ソリューションに統合する方法やオンラインでファイルをマージする方法を学習する必要がある場合は、クロスプラットフォームの PS Merger ツールを試すことができます。 .

PS ファイルと EPS ファイルをマージするには、次のものが必要です。

  • Aspose.Page for C++ API は、C++ プラットフォーム向けの機能が豊富で強力で使いやすいドキュメント操作および変換 API です。

  • 最新バージョンを直接ダウンロードできます。NuGet パッケージ マネージャーを開き、Aspose.Page.Cpp を検索してインストールします。パッケージ マネージャー コンソールから次のコマンドを使用することもできます。

Package Manager Console Command


    PM> Install-Package Aspose.Page

PostScript ファイルを C++ とマージする手順

  1. PDF 出力および PostScript 入力ストリームを初期化します。
  2. マージする PS ファイルの配列を作成します。
  3. PdfSaveOptions クラスを使用して、必要なパラメーターを指定します。このクラスを使用すると、マージ中に追加のパラメーターを設定できます。
  4. 以前に作成した出力ストリームから PdfDevice のインスタンスを作成し、サイズと画像形式を指定します。
  5. ファイルをマージします。この機能の詳細については、Aspose.Page ドキュメント にアクセスしてください。

PS を PDF にマージする C++ コード

    using Aspose::Page::IO;
    using Aspose::Page::Presentation::Pdf;
    // Initialize PDF output stream
    System::SharedPtr<System::IO::FileStream> pdfStream = System::MakeObject<System::IO::FileStream>(outDir() + u"outputPDF_out.pdf", System::IO::FileMode::Create, System::IO::FileAccess::Write);
    
    // Initialize PostScript input stream
    System::SharedPtr<System::IO::FileStream> psStream = System::MakeObject<System::IO::FileStream>(dataDir() + u"input.ps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
    System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(psStream);

    // Create an array of PostScript files that will be merged with the first one
    System::ArrayPtr<System::String> filesForMerge = System::MakeArray<System::String>({dataDir() + u"input2.ps", dataDir() + u"input3.ps"});
 
    //Initialize options object with necessary parameters.
    System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(suppressErrors);
    // If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
    options->set_AdditionalFontsFolders(System::MakeArray<System::String>({ u"{FONT_FOLDER}" }));

    // Default page size is 595x842 and it is not mandatory to set it in PdfDevice
    System::SharedPtr<Aspose::Page::EPS::Device::PdfDevice> device = System::MakeObject<Aspose::Page::EPS::Device::PdfDevice>(pdfStream);


    {
	    auto __finally_guard_0 = ::System::MakeScopeGuard([&psStream, &pdfStream]()
	    {
		    psStream->Close();
		    pdfStream->Close();
	    });

	    try
	    {
		    document->Merge(filesForMerge, device, options);
	    }
	    catch (...)
	    {
		    throw;
	    }
    }

カプセル化された PostScript ファイルを C++ とマージする

EPS を PDF に結合するには、PS から PDF への結合と同じ手順を実行する必要があります。より詳細なコード例については、Aspose.Page ドキュメント を参照してください。

EPS を PDF にマージする C++ コード

    // Initialize PDF output stream
    System::SharedPtr<System::IO::FileStream> pdfStream = System::MakeObject<System::IO::FileStream>(outDir() + u"outputPDF_out.pdf", System::IO::FileMode::Create, System::IO::FileAccess::Write);
    
    // Initialize EPS input stream
    System::SharedPtr<System::IO::FileStream> psStream = System::MakeObject<System::IO::FileStream>(dataDir() + u"input.eps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
    System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(psStream);

    // Create an array of EPS files that will be merged with the first one
    System::ArrayPtr<System::String> filesForMerge = System::MakeArray<System::String>({dataDir() + u"input2.eps", dataDir() + u"input3.eps"});
 
    //Initialize options object with necessary parameters.
    System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(suppressErrors);
    // If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
    options->set_AdditionalFontsFolders(System::MakeArray<System::String>({ u"{FONT_FOLDER}" }));

    // Default page size is 595x842 and it is not mandatory to set it in PdfDevice
    System::SharedPtr<Aspose::Page::EPS::Device::PdfDevice> device = System::MakeObject<Aspose::Page::EPS::Device::PdfDevice>(pdfStream);


    {
	    auto __finally_guard_0 = ::System::MakeScopeGuard([&psStream, &pdfStream]()
	    {
		    psStream->Close();
		    pdfStream->Close();
	    });

	    try
	    {
		    document->Merge(filesForMerge, device, options);
	    }
	    catch (...)
	    {
		    throw;
	    }
    }

PS PS ファイル形式とは

PS 形式は、ページ記述言語 (PDL) 形式の 1 つです。ページにグラフィック情報とテキスト情報を含めることができます。そのため、ほとんどの画像編集プログラムでこの形式がサポートされていました。 Postscript ファイル自体は、プリンターに対する一種の命令です。そのページから何をどのように印刷するかに関する情報が含まれています。