我正在使用html-pdf节点模块通过nodemailer生成pdf和电子邮件。一切都在工作文件中。我现在面临的唯一一个问题是我无法设置生成的pdf文件的名称。我正在附加用于生成pdf函数的代码。
const generatePdf = (data, user, startDate, endDate, linkRes) => {
return new Promise((res, rej) => {
console.log("*&&&&& Here in generate Report", linkRes);
const body = renderToString( <App meetingsData={data} userData={user} startDate={startDate} endDate={endDate} linkRes={linkRes} /> );
const title = 'Therify Meeting Report';
let returnObj = {};
const phantomPath = require('witch')('phantomjs-prebuilt', 'phantomjs');
const html = Html({body, title});
console.log("*&&&&& path", phantomPath);
const options = {
format: 'A4',
orientation: 'portrait',
// phantomPath: `${phantomPath}`,
header: {
"height": "3mm",
},
footer: {
"height": "5mm",
"contents": {
default: '<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>',
}
},
};
pdf.create(html, options).toBuffer(function (err, file) {
console.log('This is a file:', file);
if(err) {
returnObj.data = `Pdf Generation Failed`;
returnObj.status = 500;
res(returnObj);
}else {
buffer = file;
returnObj.data = `Pdf Generated Successfully`;
returnObj.status = 200;
res(returnObj);
}
});
});
}
答案 0 :(得分:0)
像这样使用
将以下代码保留在pdf.create函数中,希望它能正常工作
res.setHeader("Content-Disposition","attachment;Abc.pdf");