Merge PostScript files to PDF using C++

You can check the quality of Aspose.Page PS merging and view the results via free online PostScipt Merger

Aspose.Page for C++ PS merger allows to merge PostScript (PS) files to PDF document on Windows and Linux.
It is necessary to do several steps in order to perform PS to PDF merge:

  1. Initialize an input stream for the first input PS file.
  2. Initialize an output stream for output PDF document.
  3. Create an array of PS files that will be merged with the first one.
  4. Create an instance of PsDocument from created earlier input stream.
  5. Use PdfSaveOptions to specify AdditionalFontsFolder and SuppressError boolean value.
  6. Create an instance of PdfDevice from created earlier output stream.
  7. Merge PostScript document as PDF with PDF save options.
  8. If SuppressErrors value was true, as it is by default, It is possible to see what errors were thrown during merging of PS to PDF and saved in Exceptions list.


Following code snippet shows how to merge PS files to PDF document in C++:

 1For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C
 2// Initialize PDF output stream
 3System::SharedPtr<System::IO::FileStream> pdfStream = System::MakeObject<System::IO::FileStream>(outDir() + u"outputPDF_out.pdf", System::IO::FileMode::Create, System::IO::FileAccess::Write);
 4// Initialize PostScript input stream
 5System::SharedPtr<System::IO::FileStream> psStream = System::MakeObject<System::IO::FileStream>(dataDir() + u"input.ps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
 6System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(psStream);
 7
 8// Create an array of PostScript file that will be merged with the first one
 9System::ArrayPtr<System::String> filesForMerge = System::MakeArray<System::String>({dataDir() + u"input2.ps", dataDir() + u"input3.ps"});
10
11// If you want to convert Postscript file despite of minor errors set this flag
12bool suppressErrors = true;
13
14//Initialize options object with necessary parameters.
15System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(suppressErrors);
16// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
17options->set_AdditionalFontsFolders(System::MakeArray<System::String>({FONT_FOLDER}));
18
19// Default page size is 595x842 and it is not mandatory to set it in PdfDevice
20System::SharedPtr<Aspose::Page::EPS::Device::PdfDevice> device = System::MakeObject<Aspose::Page::EPS::Device::PdfDevice>(pdfStream);
21// But if you need to specify size and image format use following line
22//System::SharedPtr<Aspose::Page::EPS::Device::PdfDevice> device = System::MakeObject<Aspose::Page::EPS::Device::PdfDevice>(pdfStream, System::Drawing::Size(595, 842));
23
24
25{
26	auto __finally_guard_0 = ::System::MakeScopeGuard([&psStream, &pdfStream]()
27	{
28		psStream->Close();
29		pdfStream->Close();
30	});
31
32	try
33	{
34		document->Merge(filesForMerge, device, options);
35	}
36	catch (...)
37	{
38		throw;
39	}
40}

See PS merge in .Net and Java.

Let’s consider PdfSaveOptions. Using this class we can assign different conversion parameters while merging PS to PDF.

Evaluate PS merging online on our PS Merger.

You can download examples and data files from GitHub.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.