Reputation: 103
I am creating a pdf file using jsPDF and jsPDF autotable but the created pdf file is empty. There are no errors, I have checked the rows if empty but they are not. I do not know why its empty when it is 43-pages long the pdf file generated
here is my code:
$scope.export = function(){
var columns = ["Name", "Cellphone", "Work Phone"];
var rows = [];
for (var i = 0; i < $scope.data.length; i++) {
rows.push({ employeename:$scope.data[i].employeename, cell_phone:$scope.data[i].cell_phone, work_phone:$scope.data[i].work_phone});
}
var doc = new jsPDF('p', 'pt');
doc.autoTable(columns, rows);
doc.save('jspdf-test312.pdf');
}
Upvotes: 2
Views: 1869
Reputation: 103
Solved it! I have been pushing an object inside a list. It should be a list within a list.
$scope.export = function(){
var columns = ["Name", "Cellphone", "Work Phone"];
var rows = [];
for (var i = 0; i < $scope.data.length; i++) {
rows.push([ $scope.data[i].employeename, $scope.data[i].cell_phone, $scope.data[i].work_phone]);
}
var doc = new jsPDF('p', 'pt');
doc.autoTable(columns, rows);
doc.save('jspdf-test312.pdf');
}
Upvotes: 3