I think the problem here is that elementTobePrinted is not what you think.
When running the code:
var elementTobePrinted = angular.element(attrs.selector)
This will return you a list of each item that meets the conditions, so you said that you have 6 of these items (“It has 6 sections”).
You tried to replace:
html2canvas(elementTobePrinted, { onrendered: function (canvas) { var doc = new jsPDF(); for(var i=1;i<elementTobePrinted.length;i++) { doc.addImage(canvas.toDataURL("image/jpeg"), 'jpeg', 15, 40, 180, 160); doc.addImage(canvas.toDataURL("image/jpeg"),'JPEG', 0, 0, 215, 40) doc.addPage(); } doc.save(attrs.fileName); }
WITH...
for(var i=0; i<elementTobePrinted.length; i++){ html2canvas(elementTobePrinted[i], { onrendered: function (canvas) { var doc = new jsPDF(); doc.addImage(canvas.toDataURL("image/jpeg"), 'jpeg', 15, 40, 180, 160); doc.addImage(canvas.toDataURL("image/jpeg"),'JPEG', 0, 0, 215, 40) doc.addPage(); doc.save(attrs.fileName); } }
The reason why I suggest this is because html2Canvas wants the SINGLE element as the first parameter, and the above example passes a list of elements (I think assuming angular.element(attrs.selector) finds all 6 sections, which you are trying to print).