If you are utilizing a Mat-Table to organize your data, the following tips will surely be beneficial: Please take note that on button click, the downloadPDF() function will execute.
import 'jspdf-autotable';
import * as jsPDF from 'jspdf';
constructor(){}
ngOnInit(){}
documentHeaders = [
'Work Order #',
'Product #',
'Asset',
'Operator',
'Task Name',
'Target Minute',
'Actual Minute',
'Productivity %',
'Status',
'Start Time',
'End Time'
];
functionCall(){
//will return an array with data which is to be displayed}
downloadPDF() {
doc.text('Some Text here ', 10, 10);
const head = [this.documentHeaders];
let tableArray = new Array();
let data = this.functionCall('PDF');
let header: string;
header = 'Shift Summary ' + formatDate(this.tDate, 'yyyy/MM/dd', 'en');
console.log(header);
const doc = new jsPDF();
doc.text(header, 10, 10);
((doc as any).autoTable as AutoTable)({
head: head,
body: data,
theme: 'grid',
styles: {
overflow: 'visible',
cellWidth: 17,
minCellWidth: 17
// fillColor: [255, 0, 0]
},
headStyles: {
cellWidth: 17,
minCellWidth: 17
},
didDrawCell: data => {
console.log(data.column.index);
}
});
doc.save(header + '.pdf');
}