Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 229279

In one project function for create pdf and download not work in another place. Why?

$
0
0

I modified my code as shown below , but no pdf generation and opening occur :frowning:

import { Component } from '@angular/core';
import { NavController, NavParams, Platform } from 'ionic-angular';
import { PropertyProvider } from '../../providers/property/property';
import { AlertController } from 'ionic-angular';

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,
              public alertCtrl: AlertController) { }
  createPdf(epayTransID,status,ReceiptDate,TaxPeriod,TotAmount,BankRefNo) {
    var docDefinition = {
      content: [
        { text: 'Payment Receipt', style: 'header' },
        { text: new Date().toTimeString(), alignment: 'right' },
 
        { text: 'Transaction ID', style: 'subheader' },
        { text: '12345678' },
 
        /*{ 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);
  }

  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();
    }
  }

 async getPaymentReceipt(uuid,bid)
  {
    this.propertyProvider.getReceiptDetails(uuid,bid)
    .then(data => {
        this.paymentDetails = data;
        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');
  }

  async ionViewDidEnter()
  {
    this.param1 = await this.navParams.get('param1');
    this.param2 = await this.navParams.get('param2');
    await this.getPaymentReceipt(this.param1,this.param2);
    this. downloadPdf();
  }

}




got error as

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'getBuffer' of null
TypeError: Cannot read property 'getBuffer' of null  

Waiting your advise

Thanks

Anes


Viewing all articles
Browse latest Browse all 229279

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>