`).join('');
resultsContainer.classList.remove('hidden');
}
window.downloadPDF = () => {
const { jsPDF } = window.jspdf;
const pdfContainer = document.getElementById('pdf-render-container');
const hypotheses = Array.from(document.querySelectorAll('.hypothesis-card')).map(card => {
return {
style: card.querySelector('.text-indigo-600').textContent,
text: card.querySelector('.text-gray-800').textContent,
};
});
if (hypotheses.length === 0) return;
const inputs = {
'Independent Variable': document.getElementById('independentVar').value,
'Dependent Variable': document.getElementById('dependentVar').value,
'Population / Context': document.getElementById('population').value,
'Expected Outcome': document.getElementById('expectedOutcome').value,
};
let inputsHtml = '';
for (const [key, value] of Object.entries(inputs)) {
inputsHtml += `
`
).join('');
const pdfContentHtml = `
`;
pdfContainer.innerHTML = pdfContentHtml;
const contentToCapture = document.getElementById('pdf-content');
html2canvas(contentToCapture, { scale: 2, useCORS: true })
.then(canvas => {
const imgData = canvas.toDataURL('image/jpeg', 0.95);
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const imgProps = pdf.getImageProperties(imgData);
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
const ratio = imgProps.width / imgProps.height;
const scaledImgHeight = pdfWidth / ratio;
let heightLeft = scaledImgHeight;
let position = 0;
pdf.addImage(imgData, 'JPEG', 0, position, pdfWidth, scaledImgHeight);
heightLeft -= pdfHeight;
while (heightLeft > 0) {
position -= pdfHeight;
pdf.addPage();
pdf.addImage(imgData, 'JPEG', 0, position, pdfWidth, scaledImgHeight);
heightLeft -= pdfHeight;
}
pdf.save('hypothesis_report.pdf');
pdfContainer.innerHTML = '';
});
};
// Analyze on load
generateHypotheses();
});
${key}: ${value}
`; } let hypothesesHtml = hypotheses.map(h => `${h.style}
${h.text}
Hypothesis Generation Report
Inputs
${inputsHtml}
Generated Hypotheses
${hypothesesHtml}Generated by Hypothesis Creator
