幻影经理无法启动所有工人

时间:2017-12-01 08:03:08

标签: express pdf phantomjs ejs html-to-pdf

我尝试使用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' },

我不知道在哪里寻找错误,请帮忙

2 个答案:

答案 0 :(得分:0)

您必须在服务器中安装“libfontconfig”。

  • macOS sierra update仅适用于phantomjs2。
  • linux可能还需要另外安装fontconfig包。

  • Centos - sudo yum install -y fontconfig

  • Debian / Ubuntu - sudo apt-get install -y libfontconfig

答案 1 :(得分:0)

我的phantom-html-to-pdf(0.5.6)有此问题。 就我而言,我的配置是:

const pdf = require("phantom-html-to-pdf")({
    // number of allocated phantomjs processes
    numberOfWorkers: 3,
    // timeout in ms for html conversion, when the timeout is reached, the phantom process is recycled
    timeout: 10000,
    // directory where are stored temporary html and pdf files
    tmpDir: __dirname + "/tmp/", 
    phantomPath: "/usr/bin/phantomjs"
});

但是我的phantomPath没用,因为在我的情况下,它们在 phantomPath 上无法执行(出于某些原因,我们有可能将其删除)。

const pdf = require("phantom-html-to-pdf")({
    // number of allocated phantomjs processes
    numberOfWorkers: 3,
    // timeout in ms for html conversion, when the timeout is reached, the phantom process is recycled
    timeout: 10000,
    // directory where are stored temporary html and pdf files
    tmpDir: __dirname + "/tmp/"
});

我的没有pha​​ntomPath的配置有效!