我正在IONIC 4中创建pdf。以下代码在Web和android上有效,但在IOS上无效。在IOS中,它会发出alert(“创建文件时出错:” + err);
.catch(err => {
this.runloading = 'hide';
alert("Error creating file: " + err);
throw err;
});
if (this.platform.is("cordova")) {
this.pdfObj.getBuffer(buffer => {
var blob = new Blob([buffer], { type: "application/pdf" });
this.file
.writeFile(this.file.externalRootDirectory, "pro.pdf", blob, {
replace: true
})
.then(fileEntry => {
this.fileOpener
.open(
this.file.externalRootDirectory + "pro.pdf",
"application/pdf"
)
.catch(err => alert("Please install pdf viewer"));
this.runloading = 'hide';
})
.catch(err => {
this.runloading = 'hide';
alert("Error creating file: " + err);
throw err;
});
});
} else {
pdfmake.createPdf(docDefinition).open();
// this.pdfObj.download();
this.runloading = 'hide';
}
答案 0 :(得分:1)
请参阅下面的此消息。有一个错误会阻止统一体验iOS上的本地文件下载。
两个选择: 1.将pdf上载到服务器,然后重新下载。 2.等待iOS13
https://github.com/eligrey/FileSaver.js/issues/375#issuecomment-460318259