`;
tabContents.forEach(tab => {
const tabClone = tab.querySelector('.bg-white').cloneNode(true);
pdfWrapper.appendChild(tabClone);
});
pdfWrapper.innerHTML += `
`;
document.body.appendChild(pdfWrapper);
try {
const canvas = await html2canvas(pdfWrapper, { scale: 2, useCORS: true, logging: false });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
const imgWidth = canvas.width;
const imgHeight = canvas.height;
const ratio = imgWidth / imgHeight;
let finalImgWidth = pdfWidth;
let finalImgHeight = pdfWidth / ratio;
if (finalImgHeight > pdfHeight) {
finalImgHeight = pdfHeight;
finalImgWidth = pdfHeight * ratio;
}
pdf.addImage(imgData, 'PNG', 0, 0, finalImgWidth, finalImgHeight);
pdf.save('First-Aid-Guide.pdf');
} catch (error) {
console.error("PDF Generation Error:", error);
} finally {
document.body.removeChild(pdfWrapper);
downloadPdfBtn.textContent = 'Download Full Guide as PDF';
downloadPdfBtn.disabled = false;
}
}
// --- Event Listeners ---
downloadPdfBtn.addEventListener('click', generatePDF);
// --- Initial Call ---
showTab(0);
});
Disclaimer:
This guide is for informational purposes only and is not a substitute for professional first aid training or medical advice. In an emergency, always call for professional medical help immediately.
