Cover Letter Creator

1 Page
↑ `); doc.close(); doc.querySelector('.pon-cl-print-content').appendChild(printContent); const cleanup = () => { btn.textContent = oldText || 'Download PDF'; btn.disabled = false; setTimeout(() => { if (iframe && iframe.parentNode) iframe.parentNode.removeChild(iframe); }, 300); iframe.contentWindow.removeEventListener('afterprint', cleanup); }; iframe.contentWindow.addEventListener('afterprint', cleanup, { once: true }); iframe.contentWindow.focus(); iframe.contentWindow.print(); // Fallback for browsers that do not fire afterprint reliably. setTimeout(() => { if (document.body.contains(iframe)) cleanup(); }, 2000); } catch (err) { console.error(err); alert('PDF could not be prepared. Please try again.'); btn.textContent = oldText || 'Download PDF'; btn.disabled = false; } }); }); }); // PNG download document.getElementById('cl-download-png').addEventListener('click', async function() { const btn = this; btn.textContent = 'Processing...'; btn.disabled = true; const pages = document.querySelectorAll('.pon-cl-page'); const canvases = []; const pagesContainer = document.getElementById('pon-cl-pages'); for (const page of pages) { const orig = pagesContainer.style.transform; pagesContainer.style.transform = 'none'; const canvas = await html2canvas(page, { scale:2, useCORS:true, backgroundColor:'#ffffff', width:A4W, height:A4H }); pagesContainer.style.transform = orig; canvases.push(canvas); } if (canvases.length === 1) { const a = document.createElement('a'); a.href = canvases[0].toDataURL('image/png'); a.download = 'Cover_Letter_Printonnow.png'; a.click(); } else { const totalH = canvases.reduce((sum,c) => sum + c.height + GAP*2, 0); const combined = document.createElement('canvas'); combined.width = canvases[0].width; combined.height = totalH; const ctx = combined.getContext('2d'); ctx.fillStyle = '#e8e8e8'; ctx.fillRect(0,0,combined.width,combined.height); let y = 0; canvases.forEach(c => { ctx.drawImage(c,0,y); y += c.height + GAP*2; }); const a = document.createElement('a'); a.href = combined.toDataURL('image/png'); a.download = 'Cover_Letter_Printonnow_all_pages.png'; a.click(); } btn.textContent = 'Download PNG'; btn.disabled = false; }); syncAllAndRender(); } init(); })();