【发布时间】:2023-03-26 05:09:01
【问题描述】:
我需要一点帮助 我想生成一个pdf报告。
我正在使用 PDFKit 节点模块
const PDFDocument = require("pdfkit");
function generatePDF(request, reply) {
let doc = new PDFDocument();
let path = __dirname + "/payments/" + "filename" + ".pdf";
doc.text = "Hello World!";
doc.text = "Hello Me!";
doc.end();
return reply(doc)
.header('Content-disposition', 'attachment; filename=' + 'payments.pdf')
}
在客户端,我尝试了很多东西:
1.
button.addEventListener("click", function (event) {
axios.get('/payment-pdf')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}, false)
2.
<a href="/payment-pdf" download>Export</a>
如何下载 PDF 文件? 这似乎是一项简单的任务,但我无法完成。
谢谢。
【问题讨论】: