小编aks*_*adi的帖子

使用 html-pdf 创建 pdf 时出错

尝试在节点 js 中使用 html-pdf 生成 pdf,但在某些记录后出现以下错误:

TypeError: Cannot read property 'on' of undefined`

events.js:183
      throw er; // Unhandled 'error' event
      ^
Error: spawn /usr/local/lib/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs EAGAIN
Run Code Online (Sandbox Code Playgroud)

代码:

    const filePathName = path.join(__dirname, '../../../views/', "invoice.ejs");
    const htmlString = fs.readFileSync(filePathName).toString();
    let options = { format: 'Letter',"timeout": 600000 };
    const ejsData = ejs.render(htmlString, data);

    return pdf.create(ejsData, options).toFile(path.join(__dirname, '../../../tmp/', data.filename), (err, response) => {
      if (err) return console.log('err',err);
      return response;
    });
Run Code Online (Sandbox Code Playgroud)

ejs node.js phantomjs html-pdf

5
推荐指数
1
解决办法
126
查看次数

标签 统计

ejs ×1

html-pdf ×1

node.js ×1

phantomjs ×1