Type Sinhala or English notes. Use $...$ for inline math, $$...$$ for display math, and logical symbols like $\overline{X}$ for X̅ (X bar).
Your formatted math and Sinhala text will appear here...
| /g, ' | ') .replace(/ | /g, ' | ');pdfContainer.innerHTML = `Student Math NotesGenerated on ${new Date().toLocaleDateString()} ${content} `;
document.body.appendChild(pdfContainer);// 2. Render the content to a single, long canvas
const canvas = await html2canvas(pdfContainer, {
scale: 2, // Higher scale for better resolution
useCORS: true,
logging: false,
backgroundColor: '#ffffff',
// Explicitly set width/height based on the container
width: pdfContainer.scrollWidth,
height: pdfContainer.scrollHeight
});const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF('p', 'mm', 'a4');
const pdfWidth = pdf.internal.pageSize.getWidth(); // 210 mm
const pdfHeight = pdf.internal.pageSize.getHeight(); // 297 mm
const margin = 10; // 10mm margin on all sides
const contentWidth = pdfWidth - (2 * margin); // 190 mm
const contentHeight = pdfHeight - (2 * margin); // 277 mm (A4 printable area)
// Calculate scaled image dimensions
const imgWidth = contentWidth;
const imgHeight = (canvas.height * imgWidth) / canvas.width;
let heightLeft = imgHeight; // Total height of the image to be printed
let position = 0; // Vertical position on the canvas image
let pageNum = 1;// 3. Loop through and add pages
while (heightLeft > 0) {
if (pageNum > 1) {
pdf.addPage();
}
// Add a cropped part of the long canvas image
// The image is added at the top margin (margin)
// The y position is negative because we are shifting the image up to show the next part
// 1.05 is a slight scaling factor adjustment to prevent small gaps/cutoffs between pages.
pdf.addImage(imgData, 'PNG', margin, margin - position, imgWidth * 1.05, imgHeight * 1.05);
heightLeft -= contentHeight;
position += contentHeight;
pageNum++;
}
// 4. Clean up
document.body.removeChild(pdfContainer);
// 5. Save PDF
pdf.save('Student_Math_Note.pdf');
} catch (error) {
console.error('PDF generation error:', error);
alert('Error generating PDF. Please ensure your notes are not excessively long or complex, and try again.');
}
}// ✅ FIXED WORD EXPORT - Simplified and reliable
function downloadWord() {
let content = tinyMCEEditor.getContent();
// Convert MathJax to Unicode
content = content
.replace(/\\overline\{X\}/g, 'X̅')
.replace(/\\overline\{A\}/g, 'A̅')
.replace(/\\overline\{B\}/g, 'B̅')
.replace(/\\overline\{([^}]*)\}/g, '$1̅')
.replace(/\\cdot/g, '·')
.replace(/\$\$\\overline\{([^}]*)\}\$\$/g, '$1̅')
.replace(/\$\\overline\{([^}]*)\}\$/g, '$1̅')
.replace(/\$\$(.*?)\$\$/g, '$1')
.replace(/\$(.*?)\$/g, '$1')
.replace(/📗|🧩|🧮|📘|📏|📊|🔄|🧹|➕|📄|🧾|📋|🔌|📚|💾|📂|🖨️/g, '')
.replace(/
|
|---|