尝试在节点 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)