+ 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) {
    	//window.print();
        
        
	   var divToPrint=component.find("printableDiv");
	   console.log('divToPrint.outerHTML: '+JSON.stringify(divToPrint.innerHTML));
	   newWin= window.open("");
	   newWin.document.write(divToPrint.outerHTML);
	   newWin.print();
	   newWin.close();
},

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("");
               newWin.document.write(pt);
               newWin.print();
               newWin.close();
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
Bullfrog84Bullfrog84

Just a note:

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

https://success.salesforce.com/ideaView?id=0873A000000CTHKQA4