views:

222

answers:

2

Hi All,

Is it possible to change the font color of text while redirecting it to WordPad?

Examples:

C:\echo greencolor >> C:\colors.rtf -----> This text should appear green in WordPad

C:\echo redcolor >> C:\colors.rtf -----> This text should appear red in WordPad

C:\echo browncolor >> C:\colors.rtf -----> This text should appear brown in WordPad

+3  A: 

RTF uses its own markup. E.g. the words blue and red in respective colors are represented as:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033
   {\fonttbl
       {\f0\fswiss\fprq2\fcharset0 Arial;}
       {\f1\fswiss\fcharset0 Arial;}
   }
   {\colortbl ;\red0\green0\blue255;\red255\green0\blue0;}
   {\*\generator Msftedit 5.41.15.1515;}
   \viewkind4\uc1\pard\cf1\f0\fs20 blue, \cf2 red\cf0\f1\par
}

So, you need to output such markup for other colors and basically create a RTF document.

dirkgently
Wow, that's some horrible markup. Maybe that's why nobody seems to use it.
Skurmedel
@Skurmedel: Actually, this is pretty readable. When you have looked at document formats like TeX, PS (better) and PDF (worse) this looks like decent.
dirkgently
Still, they are a bit more potent than RTF :)
Skurmedel
+1  A: 

dirkgently is entirely correct. To take your examples, the following command line will produce a RTF document at C:\colors.rtf, containing the word 'green' in green.

C:\>echo {\rtf1\ansi\deff0{\fonttbl{\f0\fswiss\fcharset0 Arial;}}{\colortbl ;\red0\green128\blue0;}{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\cf1\lang1033\f0\fs20 green\cf0\par} >> c:\colors.rtf

You can then open c:\colors.rtf in Wordpad.

Colin Pickard