Created
June 2, 2021 01:31
-
-
Save enappd/36b5878c3b9dc0647740695cba2f0a7a to your computer and use it in GitHub Desktop.
Ionic app PDF generation - PDF Download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, Input } from '@angular/core'; | |
import { ModalController } from '@ionic/angular'; | |
import { PDFGenerator } from '@ionic-native/pdf-generator/ngx'; | |
@Component({ | |
selector: 'app-invoice', | |
templateUrl: './invoice.component.html', | |
styleUrls: ['./invoice.component.scss'], | |
}) | |
export class InvoiceComponent implements OnInit { | |
@Input() order; | |
content: string; | |
constructor(private modalContrller: ModalController, private pdfGenerator: PDFGenerator) { | |
} | |
closeModal() { | |
this.modalContrller.dismiss(); | |
} | |
downloadInvoice() { | |
this.content = document.getElementById('PrintInvoice').innerHTML; | |
let options = { | |
documentSize: 'A4', | |
type: 'share', | |
// landscape: 'portrait', | |
fileName: 'Order-Invoice.pdf' | |
}; | |
this.pdfGenerator.fromData(this.content, options) | |
.then((base64) => { | |
console.log('OK', base64); | |
}).catch((error) => { | |
console.log('error', error); | |
}); | |
} | |
ngOnInit() { | |
console.log('Invoice Page2', this.order); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment