Hợp nhất các tài liệu PS thành PDF

Giải pháp API C++ để kết hợp một số tệp PostScript

 

Định dạng tệp PostScript có thể chứa nhiều trang, nhưng nó không có khả năng kết hợp nhiều tệp vào một tài liệu như định dạng XPS. Giải pháp API Aspose.Page cho C++ cung cấp cho bạn chức năng hợp nhất một số tệp PS hoặc EPS vào một tài liệu PDF.

Ví dụ mã sau minh họa cách hợp nhất các tệp PostScript bằng C++. Nếu cần tìm hiểu cách tích hợp chức năng này vào một giải pháp web hoặc để hợp nhất các tệp trực tuyến, thì bạn có thể dùng thử công cụ PS Merger đa nền tảng .

Để hợp nhất các tệp PS và EPS, chúng tôi cần:

  • Aspose.Page cho API C++ là API chuyển đổi và thao tác tài liệu giàu tính năng, mạnh mẽ và dễ sử dụng cho nền tảng C++.

  • Bạn có thể trực tiếp tải xuống phiên bản mới nhất của nó, chỉ cần mở trình quản lý gói NuGet, tìm kiếm Aspose.Page.Cpp và cài đặt. Bạn cũng có thể sử dụng lệnh sau từ Bảng điều khiển quản lý gói.

Package Manager Console Command


    PM> Install-Package Aspose.Page

Các bước để hợp nhất các tệp PostScript với C ++

  1. Khởi tạo đầu ra PDF và luồng đầu vào PostScript.
  2. Tạo một mảng các tệp PS để hợp nhất.
  3. Sử dụng Lớp PdfSaveOptions để chỉ định các tham số cần thiết. Lớp này cho phép bạn đặt các tham số bổ sung trong khi hợp nhất.
  4. Tạo phiên bản của PdfDevice từ luồng đầu ra đã tạo trước đó và chỉ định kích thước cũng như định dạng hình ảnh.
  5. Hợp nhất các tập tin. Để tìm hiểu thêm về chức năng này, hãy truy cập Aspose.Page Tài liệu .

Mã C++ để hợp nhất PS thành 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;
	    }
    }

Hợp nhất các tệp PostScript được đóng gói với C ++

Để hợp nhất EPS sang PDF, bạn sẽ cần thực hiện các bước tương tự như đối với việc hợp nhất PS sang PDF. Để tìm hiểu ví dụ mã chi tiết hơn, hãy truy cập Aspose.Page Tài liệu .

Mã C++ để hợp nhất EPS thành 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 Những gì là PS Tập Tin Định Dạng

Định dạng PS là một trong những định dạng ngôn ngữ mô tả trang (PDL). Nó có khả năng chứa thông tin đồ họa cũng như văn bản trên trang. Đó là lý do tại sao định dạng được hỗ trợ bởi hầu hết các chương trình để chỉnh sửa hình ảnh. Bản thân tệp tái bút là một loại hướng dẫn cho máy in. Nó chứa thông tin về cái gì và cách in từ trang của nó.