`; // Create off-screen iframe, write the printHTML, then call print const iframe = document.createElement('iframe'); Object.assign(iframe.style, { position: 'fixed', width: '0', height: '0', border: 'none', right: '0', bottom: '0' }); document.body.appendChild(iframe); const doc = iframe.contentWindow.document; doc.open(); doc.write(printHTML); doc.close(); const imgInFrame = doc.getElementById('print-header').querySelector('img'); imgInFrame.onload = () => { iframe.contentWindow.focus(); iframe.contentWindow.print(); setTimeout(() => iframe.remove(), 500); }; imgInFrame.onerror = () => { alert('Failed to load header in print preview.'); iframe.remove(); }; }); container.appendChild(btn); } setInterval(addPrintButton, 500); })();