问题描述
使用 pdfkit 创建 PDF 文件。
节点 -v v14.16.1
节点 -v v14.16.1
我正在尝试根据 get 请求创建 pdf 文件。
index.js 文件:
app.get('/createpdf/:listId',function(req,res) {
pdf.createPdf(req.params.listId)
.then(r => {
res.sendFile(r);
});
});
pdf 创建者文件(索引中需要)
async function createInvoice(listId,invoice,path) {
let doc;
try {
doc = new PDFDocument({ margin: 50 });
await generateHeader(doc);
await generateCustomerinformation(listId,doc,invoice);
await generateInvoiceTable(doc,invoice);
} catch (e) {
console.log('createInvoice error:',e);
} finally {
doc.end();
doc.pipe(fs.createWriteStream(path));
}
}
初始化 get 请求后,nodejs 重新启动,没有错误。创建了 0 字节的 PDF 文件。可能是异步问题。 如果我通过控制台运行 pbf.js,效果很好,会创建 pdf。但是通过快递没有结果。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)