0
我目前在一個小項目中工作。我正在嘗試在我的android手機中使用ionic2+angular2(typescript)
生成pdf。我正在使用pdf製作。Pdf generation in ionic2
這裏是我的代碼:
getPdf() {
var docDefinition = { content: 'This is an sample PDF printed with pdfMake' };
pdfMake.createPdf(docDefinition).getBuffer((buffer) => {
var utf8 = new Uint8Array(buffer); // Convert to UTF-8...
let binaryArray = utf8.buffer; // Convert to Binary...
let fileName = "file.pdf";
let saveDir = cordova.file.externalApplicationStorageDirectory;
File.createFile(saveDir, fileName, true).then((fileEntry) => {
fileEntry.createWriter((fileWriter) => {
fileWriter.onwriteend =() => {
let toast = this.toastCtrl.create({
message: 'PDF gerado com sucesso! Abrindo arquivo...',
duration: 2000,
position: 'middle'
});
toast.onDidDismiss(() => {
cordova.plugins.fileOpener2.open(
saveDir+fileName,
'application/pdf');
});
//this.navCtrl.present(toast);
toast.present();
};
fileWriter.onerror = (e) => {
console.log('file writer - error event fired: ' + e.toString());
};
fileWriter.write(binaryArray);
});
});
});
}
它顯示在createWriter
錯誤物業createWriter
不上FileEntry|FileError
類型存在。
你的代碼工作正常 –