I want to have pdf export in my ionic app. In my .ts file, I have this function:
exportPDF() {
var docDefinition = {
content: [
{
layout: 'lightHorizontalLines', // optional
table: {
// headers are automatically repeated if the table spans over multiple pages
// you can declare how many rows should be treated as headers
headerRows: 1,
widths: [ '*', 'auto', 100, '*', 'auto' ],
body: [
[ 'Title 1', 'Title 2', 'Title 3', 'Title 4', 'Title 5' ],
[ 'Value 1', 'Value 2', 'Value 3', 'Value 4', 'Value 5' ],
[ 'Value 1', 'Value 2', 'Value 3', 'Value 4', 'Value 5' ],
]
}
}
]
}
pdfMake.createPdf(docDefinition).open();
pdfMake.createPdf(dd).download();
pdfMake.createPdf(docDefinition).getBuffer((buffer) => {
var utf8 = new Uint8Array(buffer); // Convert to UTF-8...
var binaryArray = utf8.buffer; // Convert to Binary...
this.file.writeFile(this.file.dataDirectory, "example.pdf", binaryArray, true).then((success) => {
alert(success.toURL());
}, (error) => {
alert(error);
});
});
}
this two lines here :
pdfMake.createPdf(docDefinition).open();
pdfMake.createPdf(dd).download();
works only on browser but not on mobile.
Now, how can I download pdf file using pdfmake and cordova-file-plugin and cordova-file-transfer-plugin?
I tried to search, but there is no definite solution.
Please help if you know the solution. Thank you very much!!!