Menggabungkan dokumen PS ke PDF

Solusi C++ API untuk menggabungkan beberapa file PostScript

 

Format file PostScript dapat berisi banyak halaman, tetapi tidak memiliki kemampuan untuk menggabungkan beberapa file menjadi satu dokumen seperti format XPS. Solusi API Aspose.Page untuk C++ memberi Anda fungsionalitas untuk menggabungkan beberapa file PS atau EPS ke dalam satu dokumen PDF.

Contoh kode berikut menunjukkan cara menggabungkan file PostScript menggunakan C++. Jika Anda perlu mempelajari bagaimana fungsi ini dapat diintegrasikan ke dalam solusi web atau untuk menggabungkan file secara online, Anda dapat mencoba fitur PS Merger lintas platform .

Untuk menggabungkan file PS dan EPS, kita membutuhkan:

  • Aspose.Page untuk C++ API yang kaya fitur, kuat, dan mudah digunakan untuk manipulasi dokumen dan API konversi untuk platform C++.

  • Anda dapat mengunduh versi terbarunya secara langsung, cukup buka pengelola paket NuGet, dan cari Aspose.Page.Cpp dan instal. Anda juga dapat menggunakan perintah berikut dari Package Manager Console.

Package Manager Console Command


    PM> Install-Package Aspose.Page

Langkah-langkah untuk menggabungkan file PostScript dengan C++

  1. Inisialisasi output PDF dan aliran input PostScript.
  2. Buat larik file PS untuk digabungkan.
  3. Gunakan Kelas PdfSaveOptions untuk menentukan parameter yang diperlukan. Kelas ini memungkinkan Anda mengatur parameter tambahan saat menggabungkan.
  4. Buat instance PdfDevice dari stream output yang dibuat sebelumnya dan tentukan ukuran dan format gambar.
  5. Gabungkan file. Untuk mempelajari lebih lanjut tentang fungsi ini, buka Aspose.Page Dokumentasi .

Kode C++ untuk menggabungkan PS ke PDF

    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;
	    }
    }

Menggabungkan file PostScript yang dienkapsulasi dengan C++

Untuk menggabungkan EPS ke PDF, Anda harus melakukan langkah yang sama seperti penggabungan PS ke PDF. Untuk mempelajari contoh kode yang lebih mendetail, buka Aspose.Page Dokumentasi .

Kode C++ untuk menggabungkan EPS ke 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 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 Apa itu Format File PS

Format PS adalah salah satu format bahasa deskripsi halaman (PDL). Hal ini mampu berisi grafis serta informasi teks pada halaman. Itulah sebabnya format ini didukung oleh sebagian besar program untuk mengedit gambar. File postscript itu sendiri adalah semacam instruksi untuk printer. Ini berisi informasi tentang apa dan bagaimana mencetak dari halamannya.