0

I want to print a specific dive content using LWC. I have tried this using javascript:

let divContents = this.template.querySelector('.voucherContainer').innerHTML;
let a = window.open('', '', 'height=500, width=500');
a.document.write('<html>');
a.document.write(divContents);
a.document.write('</body></html>');
a.document.close();
a.print();

AND

printContents =this.template.querySelector('.voucherContainer').innerHTML;
originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;

above codes are not working for LWC. What is the correct way to do this?

2 Answers 2

1

I have found a solution. We can use class="slds-no-print" to hide the sections from print. check this link Thank You.

0

document.body.innerHTML deosn't work in lwc. Use slds-no-print class in every div except you want to print.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .