' ); doc.close(); // Wait for images to load, then print var images = doc.querySelectorAll('img'); var loaded = 0; var total = images.length; var triggerPrint = function () { iframe.contentWindow.focus(); iframe.contentWindow.print(); // Clean up after print dialog closes setTimeout(function () { document.body.removeChild(iframe); }, 1000); }; if (total === 0) { triggerPrint(); return; } for (var j = 0; j < total; j++) { images[j].onload = images[j].onerror = function () { if (++loaded >= total) triggerPrint(); }; } }); }); }; // Override cmdPrint button when watermark is configured const printBtn = document.querySelector('li.fnav-item.cmdPrint a'); if (printBtn && window._epWmConfig && window._epWmConfig.text) { var _epPrintBusy = false; printBtn.addEventListener('click', function (e) { if (_epPrintBusy) return; // let default 3D FlipBook handler run on fallback re-click e.preventDefault(); e.stopImmediatePropagation(); _epPrintBusy = true; _epWatermarkPrint(dataFile, window._epWmConfig) .catch(function (err) { console.error('EmbedPress: Watermarked print failed, falling back to default', err); // Re-trigger click without our interception so 3D FlipBook handles it _epPrintBusy = true; printBtn.click(); }) .finally(function () { _epPrintBusy = false; }); }, true); }