【发布时间】: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