Friends,
I tried to open a pdf on last step of a payment, it work initially before integration , but after it’s not work
my code is
import { Component } from '@angular/core';
import { NavController, NavParams, Platform } from 'ionic-angular';
import { PropertyProvider } from '../../providers/property/property';
import pdfMake from 'pdfmake/build/pdfmake';
import pdfFonts from 'pdfmake/build/vfs_fonts';
pdfMake.vfs = pdfFonts.pdfMake.vfs;
import { File } from '@ionic-native/file';
import { FileOpener } from '@ionic-native/file-opener';
/**
* Generated class for the PaymentReceiptPage page.
*
* See http://ionicframework.com/docs/components/#navigation for more info
* on Ionic pages and navigation.
*/
@Component({
selector: 'page-payment-receipt',
templateUrl: 'payment-receipt.html',
})
export class PaymentReceiptPage {
pdfObj = null;
param1 : any;
param2 : any;
paymentDetails: any;
constructor(public navCtrl: NavController, public navParams: NavParams , public propertyProvider: PropertyProvider, private plt: Platform, private file: File, private fileOpener: FileOpener) {
this.param1 = navParams.get('param1');
this.param2 = navParams.get('param2');
// alert("got value:"+JSON.stringify(this.param1));
this.getPaymentReceipt(this.param1,this.param2);
// alert("yes:"+this.paymentDetails);
//this.createPdf();
}
createPdf(epayTransID,status,ReceiptDate,TaxPeriod,TotAmount,BankRefNo) {
// alert("Taxperiod: "+TaxPeriod);
var docDefinition = {
content: [
{ text: 'Payment Receipt', style: 'header' },
{ text: new Date().toTimeString(), alignment: 'right' },
{ text: 'Transaction ID', style: 'subheader' },
{ text: epayTransID },
{ text: 'Status', style: 'subheader' },
{ text: status },
{ text: 'Receipt Date', style: 'subheader'},
{ text: ReceiptDate },
{ text: 'Tax Period', style: 'subheader'},
{ text: TaxPeriod },
{ text: 'Total Amount', style: 'subheader'},
{ text: TotAmount},
{ text: 'Bank Reference no', style: 'subheader'},
{ text: BankRefNo},
],
styles: {
header: {
fontSize: 18,
bold: true,
},
subheader: {
fontSize: 14,
bold: true,
margin: [0, 15, 0, 0]
},
story: {
italic: true,
alignment: 'center',
width: '50%',
}
}
}
this.pdfObj = pdfMake.createPdf(docDefinition).getBlob(buffer => {
this.file.resolveDirectoryUrl(this.file.externalRootDirectory)
.then(dirEntry => {
this.file.getFile(dirEntry, 'paymentreceipt.pdf', { create: true })
.then(fileEntry => {
fileEntry.createWriter(writer => {
writer.onwrite = () => {
this.fileOpener.open(fileEntry.toURL(), 'application/pdf')
.then(res => { })
.catch(err => {
});
}
writer.write(buffer);
})
})
.catch(err => {
});
})
.catch(err => {
});
}).open();
//this.downloadPdf();
}
downloadPdf() {
if (this.plt.is('cordova')) {
this.pdfObj.getBuffer((buffer) => {
var blob = new Blob([buffer], { type: 'application/pdf' });
// Save the PDF to the data Directory of our App
this.file.writeFile(this.file.dataDirectory, 'paymentreceipt.pdf', blob, { replace: true }).then(fileEntry => {
// Open the PDf with the correct OS tools
this.fileOpener.open(this.file.dataDirectory + 'paymentreceipt.pdf', 'application/pdf');
})
});
} else {
// On a browser simply use download!
this.pdfObj.download();
}
}
getPaymentReceipt(uuid,bid)
{
//alert("getPaymentReceipt uuid is:"+uuid);
//alert("getPaymentReceipt bid is :"+bid);
this.propertyProvider.getReceiptDetails(uuid,bid)
.then(data => {
this.paymentDetails = data;
//alert("data us:"+JSON.stringify(data));
// alert(data[0].epayTransID);
let epayTransID = data[0].epayTransID;
let status = data[0].status;
let ReceiptDate = data[0].ReceiptDate;
let TaxPeriod = data[0].TaxPeriod;
let TotAmount = data[0].TotAmount;
let BankRefNo = data[0].BankRefNo;
this.createPdf(epayTransID,status,ReceiptDate,TaxPeriod,TotAmount,BankRefNo);
});
}
ionViewDidLoad() {
console.log('ionViewDidLoad PaymentReceiptPage');
}
}
Please any body advise
Thanks
Anes