Merge PS documents to PDF

C++ API solution to combine several PostScript files

 

PostScript file format can contain multiple pages, but it does not have the capability to combine multiple files into a single document like the XPS format. Aspose.Page API solution for C++ provides you with the functionality to merge several PS or EPS files into one PDF document.

The following code example demonstrates how to merge PostScript files using C++. If you need to learn how this functionality can be integrated into a web solution or to merge files online, you can try the cross-platform PS Merger tool.

To merge PS and EPS files, we need:

  • Aspose.Page for C++ API which is a feature-rich, powerful and easy to use document manipulation and conversion API for C++ platform.

  • You can download its latest version directly, just open NuGet package manager, and search for Aspose.Page.Cpp and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command

    PM> Install-Package Aspose.Page.Cpp

Steps to merge PostScript files with C++

  1. Create an instance of PsDocument from the first PostScript file.
  2. Create an array of PS files that will be merged with the first one.
  3. Use PdfSaveOptions to specify AdditionalFontsFolder and SuppressError boolean value.
  4. Merge (by MergeToPdf ) PS files with the created document and save it as PDF with PDF save options.
  5. If the SuppressErrors value was true, as it is by default, It is possible to see what errors were thrown during the merging of PostScript files to a PDF document and saved in the Exceptions list.
Merge PS files to PDF
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentMerging();
// Initialize PS document with the first PostScript file
System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(dataDir + u"input.ps");
// 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"});
// If you want to convert Postscript file despite of minor errors set this flag
bool suppressErrors = true;
//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 SaveOptions
// But if you need to specify the page size following line
//PdfSaveOptions options = new PdfSaveOptions(suppressErrors, new Aspose.Page.Drawing.Size(595, 842));
document->MergeToPdf(dataDir + u"output/" + u"outputPDF_out.pdf", filesForMerge, options);
//Review errors
if (suppressErrors)
{
for (auto&& ex : System::IterateOver(options->get_Exceptions()))
{
System::Console::WriteLine(ex->get_Message());
}
}

Merge Encapsulated PostScript files with C++

To merge EPS to PDF you will need to take the same steps as for PS to PDF merging. To learn a more detailed code example go to Aspose.Page Documentation .

PS What is PS File Format

PS format is one of the page description language (PDL) formats. It is capable to contain graphic as well as text information on the page. That is why the format was supported by most of the programs for image editing. The postscript file itself is a kind of instruction for printers. It contains information on what and how to print from its page.