当我尝试使用节点包'dynamic-html-pdf'从HTML生成PDF时,给出错误'错误:仅在Windows中写入EPIPE',而在Ubuntu16.04 LTS上它可以正常工作。
我尝试在options变量中设置phantomjs路径,还尝试以下命令
npm rebuild phantomjs-prebuilt
代码段:
var options = {
format: "A4",
orientation: "portrait",
border: "10mm",
phantomPath: 'D:\\TestFolder\\node_modules\\phantomjs-prebuilt\\bin\\phantomjs',
script: path.join(path.resolve(),'\\node_modules\\html-pdf\\lib\\scripts', 'pdf_a4_portrait.js')
};
// Router middleware
router.use(function(req,res,next) {
next();
});
router.use("/pdf",function(req,res,next){
next();
});
router.post('/pdf', async (req,res) => {
var document = {
type: 'file',
template: '<html><body>'+req.body.html+'</body></html>',
context: {
options: {
},
},
path:".\\upload\\"+req.body.erID+"\\"+req.body.sqsID+".pdf"
};
pdf.create(document, options)
.then(res1 => {
res.json(res1);
})
.catch(error => {
console.error("Error asdf :: "+error)
});
});