使用 JavaScript 将 PS/EPS 文件合并为 PDF
检查 Aspose.Page PS/EPS 合并的质量并查看结果。通过 C++ PS/EPS 合并器,Aspose.Page for JavaScript 允许在 Windows 和 Linux 系统上将封装的 PostScript (EPS) 文件合并为 PDF 文档。
执行 PS/EPS 到 PDF 合并需要执行以下步骤:
- 创建文件读取器“const file_reader = new FileReader();”并读取文件“file_reader.readAsArrayBuffer(e.target.files[0]);”。 2. 使用 AsposePagePrepare 加载所需文件
- 加载最后一个文件后,调用 AsposePSMergeToPdf,并将文件名数组、结果文件名和 SuppressError 布尔值传递给它。
- 结果 JSON 包含 fileNameResult 中的文件名。
- 如果 SuppressErrors 值为 true(默认情况下),则可以查看 EPS 合并为 PDF 时抛出的错误。
- 您可以使用 DownloadFile 函数下载文件:“DownloadFile(JSON.fileNameResult, “image/pdf”);”
以下代码片段展示了如何使用 JavaScript 将 EPS 文件合并为 PDF 文档:
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 }
让我们来考虑一些参数。
- SuppressError 控制 EPS 到 PDF 合并过程中出现非严重错误时的行为。如果该值为 true,则可以在合并后在 Exceptions 字段中查看此类错误列表。默认值为 true。