【发布时间】:2017-12-01 08:03:07
【问题描述】:
我尝试使用 phamton-html-to-pdf 和 ejs 创建一个 pdf 模板。该设置在我的本地开发环境中工作得很好,但在生产环境中却没有。问题是在我的服务器 prod 中创建了 pdf 但它是空的。
const ejs = require('ejs');
const fs = require('fs');
const conversion = require("phantom-html-to-pdf")({
phantomPath: require("phantomjs-prebuilt").path
});
function createPdf (data, template, directory) {
var options = {};
var html = ejs.renderFile(__dirname + `/template/${template}.ejs`, {data: data}, options, function(err, str){
if(err){
return err
}
return str
});
var filepath = null
conversion({ html: html, printDelay: 5000}, (err, pdf) => {
var output = fs.createWriteStream(`documents/${directory}/${data.Référence}.pdf`)
pdf.stream.pipe(output);
});
}
module.exports = createPdf;
{ Error: phantom manager could not start all workers..
at /home/website/group-auto.com/node_modules/phantom-workers/lib/phantomManager.js:66:47
at /home/website/group-auto.com/node_modules/phantom-workers/lib/phantomWorker.js:115:24
at /home/website/group-auto.com/node_modules/phantom-workers/lib/phantomWorker.js:140:20
at Socket.<anonymous> (/home/website/group-auto.com/node_modules/phantom-workers/lib/checkPortStatus.js:45:9)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at TCP._handle.close [as _onclose] (net.js:497:12)
[ { Error: Command failed: /home/website/group-auto.com/node_modules/phantom-workers/node_modules/phantomjs/lib/phantom/bin/phantomjs --ignore-ssl-errors=yes --web-security=false --ssl-protocol=any /home/website/group-auto.com/node_modules/phantom-html-to-pdf/lib/scripts/serverScript.js
/home/website/group-auto.com/node_modules/phantom-workers/node_modules/phantomjs/lib/phantom/bin/phantomjs: 1: /home/website/group-auto.com/node_modules/phantom-workers/node_modules/phantomjs/lib/phantom/bin/phantomjs: Syntax error: word unexpected (expecting ")")
at ChildProcess.exithandler (child_process.js:198:12)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:920:16)
at Socket.<anonymous> (internal/child_process.js:351:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at Pipe._handle.close [as _onclose] (net.js:497:12)
killed: false,
code: 2,
signal: null,
cmd: '/home/website/group-auto.com/node_modules/phantom-workers/node_modules/phantomjs/lib/phantom/bin/phantomjs --ignore-ssl-errors=yes --web-security=false --ssl-protocol=any /home/website/group-auto.com/node_modules/phantom-html-to-pdf/lib/scripts/serverScript.js' },
我不知道在哪里寻找错误,请帮助
【问题讨论】:
-
我面临同样的问题。你找到解决方案了吗?
标签: express pdf phantomjs ejs html-to-pdf