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:

Post a Comment

NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...

ALL comments are moderated. I will review every comment before it will appear on the blog.

Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...

I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...

Please see my comment policy for more information if you are interested.

Thanks,
Greg

PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...