【问题标题】:Phantom manager could not start all workers幻影经理无法启动所有工作人员
【发布时间】: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


【解决方案1】:

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

  • macOS sierra 更新仅适用于 phantomjs2。
  • linux 可能需要额外安装 fontconfig 包。

  • Centos - sudo yum install -y fontconfig

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

【讨论】:

    【解决方案2】:

    我在使用 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/"
    });
    

    我没有 phantomPath 的配置有效!

    【讨论】:

      猜你喜欢
      • 2015-01-20
      • 2023-02-08
      • 1970-01-01
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多