Wednesday, November 12, 2008

RichText Builder – Think StringBuilder for RTF; build a RTF document just like you would build a StringBuilder string

CodeProject - RichText Builder (StringBuilder 4 rtf)

“…

Rich Text is ubiquitous in windows forms applications yet notoriously hard to manipulate programatically. Display of Rich Text is based on the RTF specification (an archaic format dating way back to early windows 3). Parsing Rich Text is beyond the scope of this article. If however you need to build up simple rich text with FontStyle, Font ,Font size Font Colour, Back Colour ,Tables , insert images and merge RTF documents then this little utility may help you.

It is based on the StringBuilder Class Design and Can be used in place of StringBuilder. It will output RTF when ToString() is Called.

Using the code

Create a new RTFBuilder and simply append text in a similar fashion to Stringbuilder usage.

Add Formatting Calls where necessary.

RTFBuilderbase sb = new RTFBuilder();
sb.AppendLine("AppendLine Basic Text");

sb.Append("append text1").Append("append text2").Append("append text3").Append("append text4").AppendLine();

sb.FStyle(FontStyle.Bold).AppendLine("Bold");

sb.FStyle(FontStyle.Italic).AppendLine("Italic");




Also included is a GDFBuilder class which can be used interchangeably with the RtfBuilder(base) in code and will generate Images that can be displayed in a paging image control(included.)



…”




Okay, that’s officially just very darn cool. What a great way to build/generate a RTF document/file.

No comments: