`;
}
// Function to download recommendations as PDF
function downloadPDF() {
// Import necessary libraries (should be loaded in the head)
const { jsPDF } = window.jspdf;
// Create a new PDF document
const doc = new jsPDF({
orientation: 'portrait',
unit: 'mm',
format: 'a4'
});
// Get the container with the recommendations
const element = document.getElementById('keyboard-mouse-tool');
// Set up PDF styling
doc.setTextColor(44, 62, 80); // Primary color
doc.setFont("helvetica", "bold");
doc.setFontSize(24);
// Add title
doc.text('Optimal Keyboard & Mouse Positioning', 105, 20, { align: 'center' });
// Add date
doc.setFontSize(12);
doc.setFont("helvetica", "normal");
const today = new Date();
doc.text(`Generated on: ${today.toLocaleDateString()}`, 105, 30, { align: 'center' });
// Add user inputs section
doc.setFontSize(16);
doc.setFont("helvetica", "bold");
doc.setTextColor(52, 152, 219); // Secondary color
doc.text('Your Setup Details', 20, 45);
// Add user input values
doc.setFontSize(12);
doc.setFont("helvetica", "normal");
doc.setTextColor(44, 62, 80); // Primary color
const feetHeight = parseInt(userHeightFeet.value);
const inchesHeight = parseInt(userHeightInches.value);
const userHeightDisplay = `${feetHeight}'${inchesHeight}"`;
doc.text(`User Height: ${userHeightDisplay}`, 25, 55);
doc.text(`Desk Height: ${heightSlider.value} inches`, 25, 62);
doc.text(`Keyboard Distance: ${keyboardDistanceSlider.value} inches`, 25, 69);
doc.text(`Keyboard Angle: ${keyboardAngleSlider.value} degrees`, 25, 76);
doc.text(`Mouse Distance: ${mouseDistanceSlider.value} inches`, 25, 83);
doc.text(`Mouse Position: ${mousePositionSelect.value === 'right' ? 'Right of Keyboard' : 'Left of Keyboard'}`, 25, 90);
// Add recommendations section
doc.setFontSize(16);
doc.setFont("helvetica", "bold");
doc.setTextColor(52, 152, 219); // Secondary color
doc.text('Your Personalized Recommendations', 20, 105);
// Add recommendation details
doc.setFontSize(12);
doc.setFont("helvetica", "normal");
doc.setTextColor(44, 62, 80); // Primary color
// Get recommendation text from the DOM
const recommendations = document.querySelectorAll('.recommendation');
let yPos = 115;
recommendations.forEach((rec) => {
const title = rec.querySelector('h3').textContent;
const content = rec.querySelector('p').textContent;
doc.setFont("helvetica", "bold");
doc.text(title, 25, yPos);
yPos += 7;
doc.setFont("helvetica", "normal");
// Handle text wrapping for recommendation content
const contentLines = doc.splitTextToSize(content, 160);
contentLines.forEach(line => {
doc.text(line, 25, yPos);
yPos += 6;
});
yPos += 5; // Extra space between recommendations
});
// Add benefits section
doc.setFontSize(16);
doc.setFont("helvetica", "bold");
doc.setTextColor(52, 152, 219); // Secondary color
doc.text('Benefits of Optimal Positioning', 20, yPos + 5);
// Add benefit items
doc.setFontSize(12);
doc.setFont("helvetica", "normal");
doc.setTextColor(44, 62, 80); // Primary color
const benefits = [
'Reduced risk of carpal tunnel syndrome and other repetitive strain injuries',
'Decreased neck and shoulder tension',
'Improved typing comfort and efficiency',
'Better long-term musculoskeletal health',
'Enhanced focus and productivity due to reduced physical discomfort'
];
yPos += 15;
benefits.forEach(benefit => {
doc.text(`• ${benefit}`, 25, yPos);
yPos += 7;
});
// Add footer with branding
doc.setFontSize(10);
doc.setTextColor(100, 100, 100);
doc.text('Generated by Optimal Keyboard & Mouse Positioning Tool', 105, 285, { align: 'center' });
// Save the PDF
doc.save('Optimal_Keyboard_Mouse_Positioning.pdf');
}
// Generate initial recommendations
generateRecommendations();
});
