';
outputHTML += '
Interests/Hobbies:
';
outputHTML += '' + generatedInterests + '
What I\'m Looking For:
';
outputHTML += '' + generatedLookingFor + '
A Fun Fact About Me:
';
outputContent.innerHTML = outputHTML;
}
function downloadPdf() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({
orientation: 'P', // Portrait
unit: 'mm',
format: 'a4'
});
const element = document.getElementById('profileOutput'); // Target the output section
// Define colors (same as CSS for consistency)
const primaryBgColor = '#e0f7fa'; // Light Aqua
const textColor = '#004d40'; // Dark Teal
const accentColor = '#00838f'; // Cyan-Teal
// jsPDF uses 0-255 for fill color
const hexToRgb = hex => hex.match(/\w\w/g).map(x => parseInt(x, 16));
doc.setFillColor(...hexToRgb(primaryBgColor));
doc.rect(0, 0, doc.internal.pageSize.getWidth(), doc.internal.pageSize.getHeight(), 'F');
// Use html2canvas to render the output div as an image/canvas
html2canvas(element, {
scale: 2, // Increase scale for better resolution in PDF
logging: false, // Disable html2canvas logging
backgroundColor: primaryBgColor // Use the background color for canvas rendering
}).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdfWidth = doc.internal.pageSize.getWidth();
const pdfHeight = doc.internal.pageSize.getHeight();
const imgWidth = pdfWidth - 30; // Leave 15mm margin on each side
const imgHeight = canvas.height * imgWidth / canvas.width;
let heightLeft = imgHeight;
let position = 15; // Starting Y position (15mm margin)
// Add the image to the PDF
doc.addImage(imgData, 'PNG', 15, position, imgWidth, imgHeight);
heightLeft -= (pdfHeight - position);
// Handle multiple pages if content exceeds one page
while (heightLeft >= 0) {
position = 15; // Reset position for new page
doc.addPage();
// Add background to the new page
doc.setFillColor(...hexToRgb(primaryBgColor));
doc.rect(0, 0, pdfWidth, pdfHeight, 'F');
doc.addImage(imgData, 'PNG', 15, position + (imgHeight - heightLeft), imgWidth, heightLeft); // Adjust position to show remaining part
heightLeft -= (pdfHeight - position);
}
// Add a title (optional)
doc.setFontSize(18);
doc.setTextColor(...hexToRgb(accentColor)); // Cyan-Teal
doc.text("Funny Dating Profile Ideas", pdfWidth / 2, 10, { align: 'center' });
doc.save('funny_dating_profile.pdf');
}).catch(error => {
console.error("Error generating PDF:", error);
alert("Could not generate PDF. Please try again.");
});
}
// Event Listeners
generateBtn.addEventListener('click', generateProfile);
randomizeBtn.addEventListener('click', generateProfile); // Randomize uses the same generation logic here
downloadPdfBtn.addEventListener('click', downloadPdf);
// Initial instruction text
outputContent.innerHTML = '' + generatedFunFact + '
Click "Generate Funny Profile" to get some ideas!
'; });