Business Email Writing Tool

Business Email Writing Tool

Generated by Business Email Writing Tool

`; outputContainer.innerHTML = formattedEmailHtml; const content = document.getElementById('pdf-content'); if (!content) return; const sanitizedFileName = recipientName.replace(/[^a-z0-9]/gi, '_').toLowerCase(); const fileName = `email_to_${sanitizedFileName}.pdf`; html2canvas(content, { scale: 2, useCORS: true, logging: false, }).then(canvas => { const imgData = canvas.toDataURL('image/jpeg', 0.95); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const imgProps = pdf.getImageProperties(imgData); const pdfPageWidth = pdf.internal.pageSize.getWidth(); const pdfPageHeight = pdf.internal.pageSize.getHeight(); // Calculate the scaled image dimensions to fit the PDF width const ratio = imgProps.width / imgProps.height; const scaledImgHeight = pdfPageWidth / ratio; let position = 0; let heightLeft = scaledImgHeight; // Add the first page pdf.addImage(imgData, 'JPEG', 0, position, pdfPageWidth, scaledImgHeight); heightLeft -= pdfPageHeight; // Add subsequent pages if the content overflows while (heightLeft > 0) { position -= pdfPageHeight; // Create a negative offset for the next part of the image pdf.addPage(); pdf.addImage(imgData, 'JPEG', 0, position, pdfPageWidth, scaledImgHeight); heightLeft -= pdfPageHeight; } pdf.save(fileName); outputContainer.innerHTML = ''; // Clean up the temporary div }).catch(error => { console.error("Error generating PDF:", error); outputContainer.innerHTML = ''; // Clean up on error }); }; // --- RUN ON LOAD --- showTab(1); });
Scroll to Top