我是节点环境的新手,并试图在nodejs中使用ghostscript [using node-gs]将pdf转换为图像,这是我正在使用的当前代码:
const spawn = require('child-process-promise').spawn;
var gs = require('gs');
var gsCall = function () {
gs()
.batch()
.nopause()
.res(150)
.executablePath('lambda-ghostscript/bin/./gs')
.option('-sPDFPassword=asdfTTT')
.device('jpeg')
.output('C:/Users/JCol/Desktop/output.jpeg')
.input('C:/Users/JCol/Desktop/NSDL_01011977.pdf')
.exec((err, stdout, stderr) => {
if (!err) {
console.log('Suceess');
} else {
console.log('gs error:', err);
}
});
};
gsCall();
但是上面的代码重新显示spawn ENOENT
错误:
Error: spawn lambda-ghostscript/bin/./gs ENOENT
at Process.ChildProcess._handle.onexit (internal/child_pr
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:6
at Function.Module.runMain (internal/modules/cjs/loader.j
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_pr
at onErrorNT (internal/child_process.js:415:16)
[... lines matching original stack trace ...]
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
package.json
{
"name": "gsTest",
"description": "gsTest",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"dependencies": {
"child-process-promise": "^2.2.1",
"fs-extra": "^9.0.0",
"gs": "https://github.com/sina-masnadi/node-gs/tarball/master"
},
"devDependencies": {
"firebase-functions-test": "^0.1.6"
},
"private": true
}
lamabada-ghostscript文件夹与index.js在同一文件夹中,并且具有这样的结构lambda-ghostscript\bin
Here's指向解决此问题的答案的链接。当我尝试使用Google Cloud Functions部署可为PDF生成缩略图的API时遇到了它。