簡體   English   中英

無法自定義“ html-pdf” npm模塊生成的PDF文件的名稱

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

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

生成的pdf文件的名稱設置為'attachment-1.pdf'。 我想改變它。 這是附帶的pdf圖片。 生成的PDF文件

像這樣使用

將下面的代碼保存在pdf.create函數中,希望它能正常工作

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM