function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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

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