`;
}
// Generate and download PDF
function generatePDF() {
// Initialize jsPDF
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({
orientation: 'portrait',
unit: 'mm',
format: 'a4'
});
const pdfContent = document.getElementById('pdf-content');
// Use html2canvas to capture the PDF content
html2canvas(pdfContent, {
scale: 2,
useCORS: true,
logging: false
}).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const imgWidth = 210; // A4 width in mm
const pageHeight = 297; // A4 height in mm
const imgHeight = canvas.height * imgWidth / canvas.width;
let heightLeft = imgHeight;
let position = 0;
pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
// Add new pages if content overflows
while (heightLeft >= 0) {
position = heightLeft - imgHeight;
pdf.addPage();
pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
}
// Save the PDF
pdf.save('Ergonomic_Chair_Settings.pdf');
// Hide loading
loadingElement.style.display = 'none';
}).catch(error => {
console.error('Error generating PDF:', error);
alert('There was an error generating your PDF. Please try again.');
loadingElement.style.display = 'none';
});
}
});
