WordPad

Welcome to the Ultimate WordPad.

Try changing the Font or Highlighting text.

When ready, download as .RTF.
Word Count: 0
'); win.document.close(); win.print(); }// --- 3. UI UPDATES --- function updateUI() { // Highlight active buttons document.querySelectorAll('.wp-btn[data-cmd]').forEach(btn => { const cmd = btn.getAttribute('data-cmd'); if (document.queryCommandState(cmd)) { btn.classList.add('active'); } else { btn.classList.remove('active'); } }); }function updateWordCount() { const text = editor.innerText || ""; const count = text.trim().split(/\s+/).filter(w => w.length > 0).length; document.getElementById('wp-word-count').innerText = count; }// Event Listeners editor.addEventListener('keyup', updateUI); editor.addEventListener('mouseup', updateUI); editor.addEventListener('input', updateWordCount);// --- 4. EXPORTS --- function downloadFile(filename, content, mimeType) { const blob = new Blob([content], { type: mimeType }); const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = filename; document.body.appendChild(link); link.click(); document.body.removeChild(link); }function downloadTXT() { downloadFile("document.txt", editor.innerText, "text/plain"); }// --- 5. ADVANCED RTF CONVERTER (Supports Fonts, Sizes, Colors, Highlights) --- function downloadRTF() { const rtf = generateRTF(editor); downloadFile("document.rtf", rtf, "application/rtf"); }function generateRTF(element) { // Define Font Table const fonts = { 'Arial': 0, 'Times New Roman': 1, 'Courier New': 2, 'Georgia': 3, 'Verdana': 4, 'Impact': 5, 'Comic Sans MS': 6, 'sans-serif': 0 }; let fontTable = "{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}{\\f1\\fnil\\fcharset0 Times New Roman;}{\\f2\\fmodern\\fcharset0 Courier New;}{\\f3\\fnil\\fcharset0 Georgia;}{\\f4\\fswiss\\fcharset0 Verdana;}{\\f5\\fnil\\fcharset2 Impact;}{\\f6\\fnil\\fcharset0 Comic Sans MS;}}"; // Define Color Table (Red, Blue, Green, Yellow, Cyan, Magenta, Black) let colorTable = "{\\colortbl ;\\red255\\green0\\blue0;\\red0\\green0\\blue255;\\red0\\green128\\blue0;\\red255\\green255\\blue0;\\red0\\green255\\blue255;\\red255\\green0\\blue255;\\red0\\green0\\blue0;\\red255\\green255\\blue255;}"; let rtf = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033" + fontTable + colorTable + "\\viewkind4\\uc1\\pard\\f0\\fs24 "; rtf += parseNodeToRTF(element); rtf += "}"; return rtf; }function parseNodeToRTF(node) { let html = ""; // Helper to get font index const getFontIndex = (family) => { const map = {'Arial':0, 'Times New Roman':1, 'Courier New':2, 'Georgia':3, 'Verdana':4, 'Impact':5, 'Comic Sans MS':6}; return map[family] !== undefined ? map[family] : 0; };// Helper to get color index const getColorIndex = (rgb) => { if(!rgb) return 7; // Default Black // Simple hex/rgb parser for demo colors if(rgb.includes('255, 0, 0') || rgb === '#ff0000') return 1; // Red if(rgb.includes('0, 0, 255') || rgb === '#0000ff') return 2; // Blue if(rgb.includes('0, 128, 0') || rgb === '#008000') return 3; // Green if(rgb.includes('255, 255, 0') || rgb === '#ffff00') return 4; // Yellow if(rgb.includes('0, 255, 255') || rgb === '#00ffff') return 5; // Cyan if(rgb.includes('255, 0, 255') || rgb === '#ff00ff') return 6; // Magenta if(rgb.includes('255, 255, 255') || rgb === '#ffffff') return 8; // White return 7; // Black/Default };// Map HTML Size (1-7) to RTF Half-Points const getSizeRtf = (size) => { // 1:16, 2:20, 3:24, 4:28, 5:32, 6:36, 7:40 const sizes = [16, 20, 24, 28, 32, 36, 40]; let idx = parseInt(size) - 1; if(idx < 0) idx = 2; if(idx > 6) idx = 6; return sizes[idx]; }node.childNodes.forEach(child => { if (child.nodeType === Node.TEXT_NODE) { let text = child.nodeValue .replace(/\\/g, "\\\\") .replace(/{/g, "\\{") .replace(/}/g, "\\}") .replace(/\n/g, " \\line "); html += text; } else if (child.nodeType === Node.ELEMENT_NODE) { const tag = child.tagName.toLowerCase(); const style = window.getComputedStyle(child); let prefix = ""; let suffix = "";// Styles if (tag === 'b' || style.fontWeight === '700' || style.fontWeight === 'bold') { prefix += "\\b "; suffix += "\\b0 "; } if (tag === 'i' || style.fontStyle === 'italic') { prefix += "\\i "; suffix += "\\i0 "; } if (tag === 'u' || style.textDecorationLine.includes('underline')) { prefix += "\\ul "; suffix += "\\ul0 "; } if (tag === 'strike' || style.textDecorationLine.includes('line-through')) { prefix += "\\strike "; suffix += "\\strike0 "; } if (tag === 'sub') { prefix += "\\sub "; suffix += "\\sub0 "; } if (tag === 'sup') { prefix += "\\sup "; suffix += "\\sup0 "; }// Font Family const fontName = style.fontFamily.replace(/['"]/g, '').split(',')[0].trim(); const fIdx = getFontIndex(fontName); if(fIdx !== 0) { prefix += `\\f${fIdx} `; suffix += `\\f0 `; } // Reset to default after// Font Size let sizeVal = child.getAttribute('size'); let fontSize = style.fontSize; let rtfSize = 24; // default if(fontSize) { let px = parseInt(fontSize); if(px < 14) rtfSize = 16; else if(px < 18) rtfSize = 20; else if(px < 24) rtfSize = 24; else if(px < 30) rtfSize = 28; else rtfSize = 36; } prefix += `\\fs${rtfSize} `; suffix += `\\fs24 `; // Reset size// Colors const color = style.color; const cIdx = getColorIndex(color); if(cIdx !== 7) { prefix += `\\cf${cIdx} `; suffix += `\\cf7 `; }// Background Color (Highlight) const bg = style.backgroundColor; const bgIdx = getColorIndex(bg); if(bgIdx !== 8 && bgIdx !== 7) { prefix += `\\highlight${bgIdx} `; suffix += `\\highlight0 `; }// Alignment (Block level) if (['div','p','h1','h2','h3','li'].includes(tag)) { const align = style.textAlign || child.getAttribute('align'); if (align === 'center') { prefix = "\\qc " + prefix; suffix += "\\pard "; } if (align === 'right') { prefix = "\\qr " + prefix; suffix += "\\pard "; } if (align === 'justify') { prefix = "\\qj " + prefix; suffix += "\\pard "; } }// Structure if (tag === 'br') html += "\\line "; else if (['div','p','h1','h2','h3','li'].includes(tag)) { html += prefix + parseNodeToRTF(child) + "\\par " + suffix; } else if (tag === 'ul' || tag === 'ol') { html += parseNodeToRTF(child); } else if (tag === 'li') { let bullet = child.parentNode.tagName === 'OL' ? "\\li0 " : "\\bullet "; html += "\\par " + bullet + parseNodeToRTF(child); } else if (tag === 'img') { html += "[Image] "; } else { html += prefix + parseNodeToRTF(child) + suffix; } } }); return html; }
Scroll to Top