I have some html contents and image and print the page on button click. When i print it first time the print preview page is empty and second time it is fine. Please help on why it is not print the page first time
Image source is base-64 format. So, due to the large content, i not able to add code snippet, Please check with demo link.
<input type="button" id="printImage" onclick=printImage() value="print" />
function printImage() {
var htmlContent = "The html code in stack-overflow exceeded. So please check with demo link for html content";
var win = window.open();
win.document.write(htmlContent);
win.document.close();
win.focus();
win.print();
win.close();
}
sample demo link
Anyone help me on this..
win.document.write(htmlContent);
win.document.close();
win.focus();
setTimeout(function(){win.print();win.close();}, 10);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With