Skip to content

Instantly share code, notes, and snippets.

@enappd
Created June 2, 2021 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enappd/36b5878c3b9dc0647740695cba2f0a7a to your computer and use it in GitHub Desktop.
Save enappd/36b5878c3b9dc0647740695cba2f0a7a to your computer and use it in GitHub Desktop.
Ionic app PDF generation - PDF Download
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