Prabhu
Prabhu

Reputation: 404

Print the page as it is in AngularJS

I have tried using the https://github.com/gilf/ngPrint directive for print. I can able to print the page but the page design is completely collapsed while printing. Is there any possible way to print the page as it is? Note: Am using Angular Material for the pages

Upvotes: 4

Views: 3319

Answers (1)

g.005
g.005

Reputation: 406

You can try the below piece of code:

function printPage() {
  var contentToPrint = document.getElementById('#myDiv').innerHTML;
  var windowPopup = window.open('', '_blank', 'width=500,height=500');
  windowPopup.document.open();
  windowPopup.document.write('<html><head><link rel="stylesheet" type="text/css" href="" /></head><body onload="window.print()">' + contentToPrint + '</body></html>');
  windowPopup.document.close();
} 

Upvotes: 4

Related Questions