简体   繁体   English

无法自定义“ html-pdf” npm模块生成的PDF文件的名称

[英]Can't customize the name of PDF file generated by 'html-pdf' npm module

I am using html-pdf node module to generate a pdf and email via nodemailer. 我正在使用html-pdf节点模块通过nodemailer生成pdf和电子邮件。 Everything is working file. 一切都在工作文件中。 Only One problem I am facing right now is that I can't set the name of my pdf file generated. 我现在面临的唯一一个问题是我无法设置生成的pdf文件的名称。 I am attaching the code for generate pdf function. 我附上了生成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); } }); }); } 

The name of the pdf file generated is set to 'attachment-1.pdf'. 生成的pdf文件的名称设置为'attachment-1.pdf'。 I want to change it. 我想改变它。 Here is a picture attached of the pdf generated. 这是附带的pdf图片。 生成的PDF文件

Use Like this 像这样使用

keep the below code inside the pdf.create function hope it will work 将下面的代码保存在pdf.create函数中,希望它能正常工作

res.setHeader("Content-Disposition","attachment;Abc.pdf");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM