Merge PS/EPS files to PDF using JavaScript
You can check the quality of Aspose.Page PS/EPS merging and view the results via free online PS Merger or EPS Merger
Aspose.Page for JavaScript via C++ PS/EPS merger allows merging Encapsulated PostScript (EPS) files to a PDF document on Windows and Linux.
It is necessary to do several steps to perform PS/EPS to PDF merge:
- Create file reader ‘const file_reader = new FileReader();’ and read file ‘file_reader.readAsArrayBuffer(e.target.files[0]);’.
- Load needed files by using AsposePagePrepare
- After the loading of the last file, call AsposePSMergeToPdf and pass the array of file names, the result file name, and SuppressError boolean values to it.
- The result JSON contains the file name in fileNameResult.
- If the SuppressErrors value was true, as it is by default, It is possible to see what errors were thrown during the merge of EPS to PDF.
- You can download files by using the DownloadFile function: ‘DownloadFile(JSON.fileNameResult, “image/pdf”);’
The following code snippet shows how to merge EPS files into a PDF document in JavaScript:
1 var fPs2Pdf = function (e) {
2 const file_reader = new FileReader();
3 function readFile(index) {
4 if (index >= e.target.files.length) {
5 const fileNames = Array.from(e.target.files).map((x) => x.name).toString();
6 const JSON = PSMergeToPdf(fileNames, "ResultMerge.pdf", true);
7 if (JSON.errorCode == 0) {
8 DownloadFile(JSON.fileNameResult, "image/pdf");
9 }
10 else
11 document.getElementById('output').textContent = JSON.errorText;
12 return;
13 }
14 const file = e.target.files[index];
15 file_reader.onload = function (event) {
16 AsposePagePrepare(event.target.result, file.name);
17 readFile(index + 1)
18 }
19 file_reader.readAsArrayBuffer(file);
20 }
21 readFile(0);
22 }
Let’s consider some parameters.
- SuppressError controls the behaviour of the EPS to PDF merger when non-critical errors appear. If the value is true, then it is possible to view a list of such errors after merging in the Exceptions field. The default value is true.
Evaluate EPS merging online on our EPS Merger.
You can download examples and data files from GitHub.