我使用下面的代码来生成pdf:
let fileUri = process.env.PWD + '/storage/orders-pdf/' + fileName;
// Commence Webshot
webshot(html_string, fileUri, options, function(error) {
fs.readFile(fileUri, function (err, data) {
if (err) {
return console.log(err);
}
fs.unlinkSync(fileUri);
fut.return(data);
});
});
let pdfData = fut.wait();但它会抛出以下错误:
{ [Error: ENOENT, open '/opt/holi/storage/orders-pdf/Attributes.pdf']
errno: 34,
code: 'ENOENT',
path: '/opt/holi/storage/orders-pdf/Attributes.pdf' }尝试使用npm包https://github.com/brenden/node-webshot,然后代码在本地主机上运行良好,但在服务器上失败,并抛出以下错误:
编辑:
即使在运行webshot时没有:
fs.readFile(fileUri, function (err, data) {
if (err) {
return console.log(err);
}
fs.unlinkSync(fileUri);
fut.return(data);
});文件未创建..
编辑-2:
Webshot抛出错误:[Error: PhantomJS exited with return value 2]
编辑-3:实际问题:https://github.com/brenden/node-webshot/issues/123
发布于 2016-02-20 03:23:44
我也遇到了类似的问题,我花了一整天的时间试图弄清楚这个问题。我最后加了一句:
"phantomPath": "/usr/bin/phantomjs"添加到我的网页截图选项对象。我使用的phantom路径是mup在服务器设置上安装phantomjs的位置。
https://stackoverflow.com/questions/35182835
复制相似问题