2016-12-05 88 views
0

我在我的Electron應用程序中使用此模塊將一些數據庫數據轉換爲HTML字符串,然後將其轉換爲PDF文件。但我想向用戶顯示「另存爲」對話框而不是將其保存到特定文件夾。我找不到使用filesaver.js的方法。任何機構能幫助我嗎?使用node-html-pdf和FileSaver.js

我試過這個使用電子對話框API,但它沒有奏效。

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

回答

0

,我發現我的問題的答案從 '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); 
     }); 

    });