Merge EPS files to PDF using C++
You can check the quality of Aspose.Page EPS merging and view the results via free online EPS Merger
Aspose.Page for C++ EPS merger allows to merge Encapsulated PostScript (EPS) files to PDF document on Windows and Linux.
It is necessary to do several steps in order to perform EPS to PDF merge:
- Create an instance of PsDocument from the first EPS file.
- Create an array of EPS files that will be merged with the first one.
- Use PdfSaveOptions to specify AdditionalFontsFolder and SuppressError boolean value.
- Merge (by MergeToPdf) EPS files with created document and save it as PDF with PDF save options.
- If SuppressErrors value was true, as it is by default, It is possible to see what errors were thrown during merging of EPS files to PDF document and saved in Exceptions list.
Following code snippet shows how to merge EPS files to PDF document in C++:
1 // The path to the documents directory.
2 System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentMerging();
3
4 // Initialize PS document with the first PostScript file
5 System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(dataDir + u"input.eps");
6
7 // Create an array of PostScript files that will be merged with the first one
8 System::ArrayPtr<System::String> filesForMerge = System::MakeArray<System::String>({dataDir + u"input2.eps", dataDir + u"input3.eps"});
9
10 // If you want to convert Postscript file despite of minor errors set this flag
11 bool suppressErrors = true;
12
13 //Initialize options object with necessary parameters.
14 System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(suppressErrors);
15 // If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
16 options->set_AdditionalFontsFolders(System::MakeArray<System::String>({u"{FONT_FOLDER}"}));
17
18 // Default page size is 595x842 and it is not mandatory to set it in SaveOptions
19 // But if you need to specify the page size following line
20 //PdfSaveOptions options = new PdfSaveOptions(suppressErrors, new Aspose.Page.Drawing.Size(595, 842));
21
22 document->MergeToPdf(dataDir + u"outputPDF_out.pdf", filesForMerge, options);
23
24 //Review errors
25 if (suppressErrors)
26 {
27 for (auto&& ex : System::IterateOver(options->get_Exceptions()))
28 {
29 System::Console::WriteLine(ex->get_Message());
30 }
31 }
Let’s consider
PdfSaveOptions. Using this class we can assign different conversion parameters while merging EPS to PDF.
- AdditionalFontsFolder specifies locations where to find fonts. System fonts folders are always included by default.
- SuppressError controls behaviour of EPS to PDF merger when non-critical errors are appeared. If value is true than it is possible to view a list of such errors after merging in Exceptions field. Default value is true.
- Debug allows outputting debug information to console. Default value is false.
Evaluate EPS merging online on our EPS Merger.
You can download examples and data files from GitHub.