将 node-html-pdf 与 FileSaver.js 一起使用

Using node-html-pdf with FileSaver.js

我在我的 Electron 应用程序中使用此模块将一些数据库数据转换为 HTML 字符串,然后将其转换为 PDF 文件。但我想向用户显示一个 'save as' 对话框,而不是将其保存到特定文件夹。我找不到使用 filesaver.js 来做到这一点的方法。任何人都可以帮助我吗?

我尝试使用电子对话框 api 但它没有用。

dialog.showSaveDialog(function(filename) {
    if (fileName === undefined) return;
    pdf.create(html).toStream(function(err, stream) {
        stream.pipe(fs.createWriteStream('file.pdf'));
    });
});

我在 'marcbachmann'

的帮助下找到了问题的答案

这是我的代码:

dialog.showSaveDialog({
      filters: [{ name: 'PDFs', extensions: ['pdf']}],
                    title: 'Save the Report as PDF',
                    defaultPath: path.join(app.getPath('desktop'), 'title1'+'.pdf')}
       , function(filename) {

       pdf.create(docx).toFile(filename,function(err, res){
              console.log(res.filename);
       });

   });