I have a list of object, while getting each element of the object, I want to export each to individual pages inside the PDF.
I am getting the data by iterating the list object(eg. $scope.employees
). Currently when a user clicks on export button, the data is exported to the PDF. My requirement is each object while iterating should be stored in the individual pages of the PDF. Like for example the object with pageHeader "This is shown in page1" should be shown in page1, "This is shown in page2" should be shown in page2 of the PDF when opened etc...
Any suggestions on this would be appreciated.
Please find a plunker demonstration here: https://plnkr.co/edit/HvKipjWCYsgujJOv6You?p=preview
Do I need to use pageSplit:true
option while iterating the $scope.employees
, any inputs?
js code:
$scope.export = function(){
alert("in pdf export");
var pdf = new jsPDF('landscape');
var width1 = pdf.internal.pageSize.width;
var height = pdf.internal.pageSize.height;
var source = "";
$scope.employees.forEach(function(value){
source+= value.pageHeader + "\n" +"\n";
})
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
margins = {
top: 80,
bottom: 60,
left: 10,
width: '100%'
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, { // y coord
'width': width1, // max width of content on PDF
'elementHandlers': specialElementHandlers
},
function (dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save('test.pdf');
},
margins
);