【问题标题】:pdfmake + AngularJS + Electron creates _blank pdfpdfmake + AngularJS + Electron 创建 _blank pdf
【发布时间】:2017-01-26 06:41:24
【问题描述】:

我在 AngularJS 和 Electron 中使用库 pdfmake 时遇到问题。 pdf保存为空白。

代码是:

.service('PDFService', function() {

   this.createPdfOne = function(data) {

    const {dialog} = require('electron').remote;
    const choice = dialog.showOpenDialog({ properties: [ 'createDirectory', 'openDirectory']});
    var docDefinition = {
        content: [
            'First paragraph',
            'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
        ]
    };

    var fs = require('fs');
    pdfMake.createPdf(docDefinition).getBuffer(function(result) {
        fs.writeFileSync(choice + '/sample.pdf', result);
    });
  };

});

更新:已修复问题

我使用:

pdfMake.createPdf(docDefinition).download()

代替:

 var fs = require('fs');
    pdfMake.createPdf(docDefinition).getBuffer(function(result) {
        fs.writeFileSync(choice + '/sample.pdf', result);
 });

【问题讨论】:

  • 据我所知,你可以使用pdfMake.createPdf(docDefinition).download('FILENAME.pdf');github.com/bpampuch/pdfmake/issues/116
  • @Jordan.J.D 谢谢,这很好用
  • 既然您确认它有效,我将其发布为答案

标签: angularjs electron pdfmake


【解决方案1】:

repo documentation 没有提到这一点,但发现here 提出了同样的问题。关闭时说您可以执行以下操作:

pdfMake.createPdf(docDefinition).download('FILENAME.pdf');

【讨论】:

    猜你喜欢
    • 2017-04-23
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 2015-02-07
    • 1970-01-01
    • 2017-12-25
    • 2014-12-31
    • 2021-08-10
    相关资源
    最近更新 更多