我正在使用 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);
}
});
});
}