-types Html2pdf.js -

function exportToPDF() // Show a temporary loading effect (optional) const originalBtnText = generateBtn.innerHTML; generateBtn.innerHTML = '<i class="fas fa-spinner fa-pulse"></i> Generating PDF...'; generateBtn.disabled = true; // Use html2pdf from the bundle html2pdf().set(pdfOpts).from(paperElement).save().then(() => generateBtn.innerHTML = originalBtnText; generateBtn.disabled = false; ).catch(err => console.error("PDF generation error: ", err); generateBtn.innerHTML = originalBtnText; generateBtn.disabled = false; alert("PDF generation error. Please check console or try again."); ); if (generateBtn) generateBtn.addEventListener('click', exportToPDF); // ---- PRINT PREVIEW using browser's print (high-fidelity) ---- const printBtn = document.getElementById('previewPrintBtn'); if (printBtn) printBtn.addEventListener('click', () => // open print dialog with a temporary style to enhance printed paper look const originalTitle = document.title; document.title = 'Neural Topology Paper - Academic Print'; window.print(); document.title = originalTitle; ); // Add optional subtle print styles (to ensure printed version looks similar) const stylePrint = document.createElement('style'); stylePrint.textContent = `@media print body background: white; padding: 0; margin: 0; .toolbar, footer, .tool-group, .info-badge, .tool-btn display: none !important; .paper-studio box-shadow: none; margin:0; padding:0; .paper-container padding: 0; background: white; #academicPaper box-shadow: none; max-width: 100%; .paper-content padding: 0.7in; [contenteditable="true"] background: white; `; document.head.appendChild(stylePrint); // (Optional) Minor auto-fix for contenteditable newlines — not needed but keeps consistent // Additional validation: ensure that any newly added content through user edits is preserved. // Since all major elements are contenteditable, the PDF will render exactly what user edits. // For better math representation, we also added inline .math class but no extra rendering. console.log("Academic paper studio ready — edit any field, then export to PDF via html2pdf.js"); )(); </script>

.paper-content .figure-caption font-size: 0.8rem; text-align: center; font-family: 'Inter', sans-serif; color: #4b5563; margin-top: 0.3rem;

// Reset functionality: restores original academic content const resetBtn = document.getElementById('resetPaperBtn'); if (resetBtn) resetBtn.addEventListener('click', () => const editableDiv = document.getElementById('editableContent'); if (editableDiv) editableDiv.innerHTML = originalContentHTML; // After reset, re-attach contenteditable attributes? Actually original HTML already has contenteditable="true" on elements. // But some dynamic innerHTML might lose reference? Since we set innerHTML exactly as original, all attributes remain. // Ensure that contenteditable elements are editable again (fine because original had them). // small optional: reapply any event if needed, but no extra events needed. );

.paper-content p margin-bottom: 0.9rem; font-size: 1.05rem; text-align: justify; hyphens: auto; -types html2pdf.js

.tool-btn i font-size: 0.95rem;

/* MAIN CONTAINER: editable paper + controls */ .paper-studio max-width: 1100px; width: 100%; background: white; border-radius: 28px; box-shadow: 0 25px 45px -12px rgba(0,0,0,0.3); overflow: hidden; transition: all 0.2s;

.info-badge background: #0f172a; padding: 6px 14px; border-radius: 40px; font-size: 0.8rem; color: #a5b4fc; font-family: monospace; function exportToPDF() // Show a temporary loading effect

/* editable effect */ [contenteditable="true"] outline: none; transition: background 0.1s ease; [contenteditable="true"]:hover background: #fffbf0; [contenteditable="true"]:focus background: #fffae6; box-shadow: inset 0 0 0 1px #cbd5e1;

/* Toolbar styling */ .toolbar background: #1e293b; padding: 1rem 2rem; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 15px; border-bottom: 1px solid #334155;

.tool-btn background: #0f172a; border: none; padding: 8px 18px; border-radius: 40px; font-family: 'Inter', sans-serif; font-weight: 500; font-size: 0.9rem; color: #f1f5f9; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; transition: all 0.2s ease; box-shadow: 0 1px 2px rgba(0,0,0,0.1); // For better math representation, we also added inline

/* Responsive */ @media (max-width: 700px) .paper-content padding: 1.4rem; .toolbar flex-direction: column; align-items: stretch; .tool-group justify-content: center; footer margin-top: 20px; font-size: 0.75rem; color: #334155; text-align: center; </style> </head> <body>

// ---- PDF GENERATION via html2pdf.js with academic options ---- const generateBtn = document.getElementById('generatePdfBtn'); const pdfOpts = margin: [0.65, 0.65, 0.65, 0.65], // top, right, bottom, left (in inches) filename: 'Neural_Topology_Paper.pdf', image: type: 'jpeg', quality: 0.98 , html2canvas: scale: 2.5, letterRendering: true, useCORS: false, logging: false , jsPDF: unit: 'in', format: 'a4', orientation: 'portrait' ;

Compartir