Skip to content

Instantly share code, notes, and snippets.

@Alexintosh
Created January 4, 2016 10:57
Show Gist options
  • Save Alexintosh/dc309ddf319be350a435 to your computer and use it in GitHub Desktop.
Save Alexintosh/dc309ddf319be350a435 to your computer and use it in GitHub Desktop.
var doc = new $window.jsPDF("p", "mm", "a4");
$timeout(function(){
$window.html2canvas( $document[0].getElementsByClassName('print-pass'), {
onrendered: function(canvas){
var imgData = canvas.toDataURL('image/png');
//Page size in mm
var pageHeight = 295;
var imgWidth = 210;
var imgHeight = canvas.height * imgWidth / canvas.width;
var heightLeft = imgHeight;
var position = 0;
doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
while (heightLeft >= 0) {
position = heightLeft - imgHeight;
doc.addPage();
doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
}
doc.autoPrint();
doc.output('dataurlnewwindow');
//doc.save( booking.bookingRef + '.pdf');
}
});
}, 1000);
@abdullahqureshi1994
Copy link

Unable to resolve $window and $timeout funtions.
Any help will be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment