`;
var tempDiv = document.createElement('div');
tempDiv.innerHTML = summaryHtml;
document.body.appendChild(tempDiv);
html2canvas(tempDiv, {
scale: 2,
useCORS: true,
backgroundColor: '#ffffff'
}).then(function(canvas) {
document.body.removeChild(tempDiv);
var imgData = canvas.toDataURL('image/png');
var doc = new jsPDF({
orientation: 'p',
unit: 'pt',
format: 'letter'
});
var pdfWidth = doc.internal.pageSize.getWidth();
var pdfHeight = doc.internal.pageSize.getHeight();
var imgProps = doc.getImageProperties(imgData);
var imgWidth = imgProps.width;
var imgHeight = imgProps.height;
var margin = 40;
var usableWidth = pdfWidth - (2 * margin);
var ratio = usableWidth / imgWidth;
var scaledHeight = imgHeight * ratio;
if (scaledHeight > pdfHeight - (2 * margin)) {
var pageHeight = pdfHeight - (2 * margin);
var heightLeft = scaledHeight;
var position = 0;
while (heightLeft > 0) {
doc.addImage(imgData, 'PNG', margin, position + margin, usableWidth, scaledHeight);
heightLeft -= pageHeight;
position -= pageHeight;
if (heightLeft > 0) {
doc.addPage();
}
}
} else {
// Single page
doc.addImage(imgData, 'PNG', margin, margin, usableWidth, scaledHeight);
}
doc.save(fileName);
}).catch(function(err) {
document.body.removeChild(tempDiv);
console.error("SMF PDF Error:", err);
alert("An error occurred while generating the PDF.");
});
});
// --- Initial Load ---
renderConfigTab();
// Initial display of the XML viewer placeholder
manifestOutput.value = generateManifestXML();
showTab(0);
});
