|
| 1 | +// Function to update the recipient's name dynamically |
| 2 | +function updateRecipientName() { |
| 3 | + const recipientNameElement = document.getElementById('recipientName'); |
| 4 | + const recipientNameInput = prompt('Enter the recipient\'s name:'); |
| 5 | + if (recipientNameInput) { |
| 6 | + recipientNameElement.textContent = recipientNameInput; |
| 7 | + } |
| 8 | +} |
| 9 | + |
| 10 | +// Function to generate and download the certificate as a PDF |
| 11 | +function downloadCertificate() { |
| 12 | + const certificate = document.querySelector('.certificate'); |
| 13 | + const opt = { |
| 14 | + margin: 0, |
| 15 | + filename: 'certificate.pdf', |
| 16 | + image: { type: 'jpeg', quality: 0.98 }, |
| 17 | + html2canvas: { scale: 2 }, |
| 18 | + jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' } |
| 19 | + }; |
| 20 | + |
| 21 | + html2pdf().from(certificate).set(opt).outputPdf().then((pdf) => { |
| 22 | + pdf.save(); |
| 23 | + }); |
| 24 | +} |
| 25 | + |
| 26 | +// Event listener to update recipient's name |
| 27 | +document.getElementById('generateCertificate').addEventListener('click', updateRecipientName); |
| 28 | + |
| 29 | +// Event listener to generate and download the certificate as PDF |
| 30 | +document.getElementById('generateCertificate').addEventListener('click', downloadCertificate); |
0 commit comments