+ Start a Discussion
Pasan   EeriyagamaPasan Eeriyagama 

How to print a div content in a Lightning component?

I'm trying to print content inside a div as below.
printPreview: function(component, event, helper) {
	   var divToPrint=component.find("printableDiv");
	   console.log('divToPrint.outerHTML: '+JSON.stringify(divToPrint.innerHTML));
	   newWin= window.open("");

But this did not work. Anyone got a working example to print within Lightning components please. Appreciate any help. Thanks.
Ramakrishna Reddy GouniRamakrishna Reddy Gouni
 var pc = component.find("printContent");
        var pt = pc.getElement().innerHTML;
        var newWin= window.open("");
Pasan   EeriyagamaPasan Eeriyagama
Hi @Ramakrishna Reddy, it's not correct, the problem is seems to bewith window.open()

That throws same error "newWin.document is undefined" . 
Pasan   EeriyagamaPasan Eeriyagama
Hi @sravanimmrao,

This is not solved at the time I'm writing this reply, there is this idea (https://success.salesforce.com/ideaView?id=0873A000000TsNQQA0)for Salesforce.

Mandy SinghMandy Singh
Did you got any solution regarding this ? @Pasan Eeriyagama

Just a note:

I asked them to merge that idea with this one, but vote for both until the get'r done.


Syed Shadab SajidSyed Shadab Sajid
Please make sure to set the component version to 39 or lower for print to work. Use IDE to set the version