如何解决使用PdfMake Ionic生成Pdf
我正在使用Ionic中的pdfMake生成pdf,pdf中有图形。在android中,没有问题的图形行出现在pdf中,但没有出现iOS的图形行。您能不能解决这个问题。
var node = document.getElementById(elementID); this.alertService.GetMessage(“ PleaseWait”)。subscribe(message => {this.waitMessage = message}); this.loading = this.loadingCtrl.create({ 内容:this.waitMessage }); this.loading.present()。then(()=> { domtoimage.toPng(node,{filter:that.filter}) .then(function(dataUrl){ // var img = new Image(); // img.src = dataUrl; console.log(“附带PDF图像源”); var docDefinition = { pageSize:“ A4”, pageMargins:[80,80,80,60],
//pageOrientation: 'landscape',header: {
margin: 25,columns: [
{
table: {
widths: ['80%','20%'],body: [
[{
table: {
widths: ['100%'],body: [
[{ text: pageTitle,alignment: 'center',color:'#fff',style: 'subheader' }],]
},layout: 'noBorders'
},{
image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMwAAABUCAYAAADOF9jcAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw',width: 80,height: 22,alignment: 'right'
}],]
},fillColor: 'red',layout: 'noBorders',},],content: [
{
image: dataUrl,width: 430,height: 620,styles: {
header: {
fontSize: 18,bold: true,color:'#FFFF',subheader: {
fontSize: 14,onlyBold:{
bold: true
}
}
}
const options: DocumentViewerOptions = {
title: 'My PDF'
}
// that.pdfObj = pdfMake.createPdf(docDefinition);
// that.saveAndOpenPdf("DURGA PRASAD","test"+".pdf")
docDefinition = null;
console.log("DownloadPdf() triggered")
that.pdfObj.getBuffer((buffer) => {
var blob = new Blob([buffer],{ type: 'application/pdf' });
that.getStoragePath().then(function (url) {
// Save the PDF to the data Directory of our App
that.file.writeFile(url,fileName+'.pdf',blob,{ replace: true }).then(fileEntry => {
// Open the PDf with the correct OS tools
that.fileOpener.open(url + fileName+'.pdf','application/pdf');
blob = null;
that.pdfObj = null;
that.loading.dismiss();
})
});
});
})
.catch(function (error) {
console.error('oops,something went wrong!',error);
});
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。