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?

0

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.