Legal Contract Redlining Tool
Compare two versions of a document to see the differences.
Comparison Result
Please provide text in at least one of the document fields to see a comparison.
'; return true; // Allow navigation to see this message } try { const dmp = new diff_match_patch(); const diff = dmp.diff_main(originalText, revisedText); dmp.diff_cleanupSemantic(diff); const html = dmp.diff_prettyHtml(diff); redlineOutput.innerHTML = html; return true; } catch (error) { console.error("Error during text comparison:", error); redlineOutput.innerHTML = 'An error occurred while generating the comparison. Please try again.
'; return false; } }; /** * Generates and downloads a PDF of the redlined output */ const downloadPDF = () => { const { jsPDF } = window.jspdf; const contentArea = document.getElementById('pdf-content-area'); if (!contentArea) { console.error('PDF content area not found.'); return; } // Add a title for the PDF that is only visible during capture const pdfTitle = document.createElement('h2'); pdfTitle.innerText = 'Legal Document Redline Comparison'; pdfTitle.className = 'text-xl font-bold text-slate-800 text-center mb-4'; contentArea.prepend(pdfTitle); html2canvas(contentArea, { scale: 2, // Improve resolution useCORS: true }).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; let newCanvasWidth = pdfWidth - 40; // with margin let newCanvasHeight = newCanvasWidth / ratio; if (newCanvasHeight > pdfHeight - 40) { newCanvasHeight = pdfHeight - 40; newCanvasWidth = newCanvasHeight * ratio; } const x = (pdfWidth - newCanvasWidth) / 2; const y = 20; pdf.addImage(imgData, 'PNG', x, y, newCanvasWidth, newCanvasHeight); pdf.save('Redlined_Contract.pdf'); // Clean up by removing the title pdfTitle.remove(); }).catch(error => { console.error('Error generating PDF:', error); pdfTitle.remove(); // Ensure cleanup on error }); }; // IV. C. Attach event listeners prevBtn.addEventListener('click', () => navigateTabs(-1)); nextBtn.addEventListener('click', () => navigateTabs(1)); downloadPdfBtn.addEventListener('click', downloadPDF); tabButtons.forEach(button => { button.addEventListener('click', () => { const tabIndex = parseInt(button.dataset.tab, 10); // Don't allow direct clicking to the results tab without generating the comparison if(tabIndex === 1) { if(generateRedline()) { showTab(tabIndex); } } else { showTab(tabIndex); } }); }); // Initial setup showTab(0); });