`;
issuesContainer.innerHTML += issueCard;
});
}
resultsSection.classList.remove('hidden');
}
// --- PDF Download Logic ---
downloadPdfBtn.addEventListener('click', () => {
const { jsPDF } = window.jspdf;
const content = document.getElementById('pdf-content');
if (!content) {
console.error("PDF content area not found.");
return;
}
html2canvas(content, {
scale: 2, // Higher scale for better resolution
backgroundColor: '#ffffff' // Ensure background is white
}).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({
orientation: 'portrait',
unit: 'pt',
format: 'a4'
});
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
const canvasWidth = canvas.width;
const canvasHeight = canvas.height;
const ratio = canvasWidth / canvasHeight;
const widthInPdf = pdfWidth - 80; // Margin of 40pt on each side
const heightInPdf = widthInPdf / ratio;
let position = 40;
pdf.addImage(imgData, 'PNG', 40, position, widthInPdf, heightInPdf);
let heightLeft = heightInPdf;
heightLeft -= (pdfHeight - 80); // Subtract first page height
while (heightLeft > 0) {
position = position - (pdfHeight - 80);
pdf.addPage();
pdf.addImage(imgData, 'PNG', 40, position, widthInPdf, heightInPdf);
heightLeft -= (pdfHeight - 80);
}
pdf.save('Grammar-Style-Report.pdf');
});
});
});
