-

-

 

Scegli il raggruppamento di classifica



`); doc.close(); // 6) Inserisci overlay watermark (PRIMA del contenuto) if (watermarkUrl) { const overlay = doc.createElement('div'); overlay.className = 'print-watermark'; const logo = doc.createElement('img'); logo.src = watermarkUrl; overlay.appendChild(logo); doc.body.appendChild(overlay); } // 7) Clona il contenuto dei div nell’iframe const cloneIntestazione = intestazione.cloneNode(true); const cloneTabella = tabella.cloneNode(true); doc.body.appendChild(cloneIntestazione); doc.body.appendChild(cloneTabella); // 8) Attendi risorse (immagini + font) dell'iframe const waitImages = Array.from(doc.images).map(img => { if (img.complete) return Promise.resolve(); return new Promise(res => { img.addEventListener('load', res, { once: true }); img.addEventListener('error', () => { console.warn('[print] immagine non caricata:', img.src); res(); }, { once: true }); }); }); const waitFonts = (doc.fonts && doc.fonts.ready) ? doc.fonts.ready.catch(() => {}) : Promise.resolve(); try { await Promise.race([ Promise.all([Promise.all(waitImages), waitFonts]), new Promise(res => setTimeout(res, 4000)) // timeout di sicurezza ]); } catch (e) { console.warn('[print] attesa risorse con errori:', e); } // 9) Stampa e pulizia win.onafterprint = () => { document.body.removeChild(iframe); }; win.focus(); try { win.print(); } catch (e) { console.error('[print] errore durante print():', e); document.body.removeChild(iframe); } }