Showing posts with label RTF. Show all posts
Showing posts with label RTF. Show all posts

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();



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.

Wednesday, July 02, 2008

Got some RTF? Want to create your own parser? Don’t want to re-invent the wheel?

CodeProject - Writing your own RTF Converter


The component introduced in this article has been designed with the following goals in mind:

  • Support for the current RTF Specification 1.9.1
  • Open source C# code
  • Unlimited usage in console, WinForms, WPF, and ASP.NET applications
  • Independence of third party components
  • Possibility to analyze RTF data on various levels
  • Separation of parsing and the actual interpretation of the RTF data
  • Extensibility of parser and interpreter
  • Providing simple predefined conversion modules for text, images, XML, and HTML
  • Ready-to-Use RTF converter applications for text, images, XML, and HTML
  • Open architecture for simple creation of custom RTF converters

Please keep the following shortcomings in mind:

  • The component offers no high-level functionality to create RTF content.
  • The present RTF interpreter is restricted to content data and basic formatting options.

    There is no special support for the following RTF layout elements:

    • Tables
    • Lists
    • Automatic numbering
    • All features which require knowledge of how MS-Word might mean it ...

In general, this should not pose a big problem for many areas of use. A conforming RTF writer should always write content with readers in mind that do not know about tags and features which were introduced later in the standards history. As a consequence, a lot of the content in an RTF document is stored several times (at least if the writer cares about other applications). This is taken advantage of by the interpreter here, which just simply focuses on the visual content. Some writers in common use, however, improperly support this alternate representation which will result in differences in the resulting output.

Thanks to its open architecture, the RTF parser is a solid base for development of an RTF converter which focuses on layout.


The thought of writing my own RTF parser makes my brain hurt. That is a wheel I don’t think I’d EVER want to re-invent.

Thursday, March 20, 2008

RTF 1.9.1 Specification

Microsoft Downloads - Word 2007: Rich Text Format (RTF) Specification, version 1.9.1


The Rich Text Format (RTF) Specification provides a format for text and graphics interchange that can be used with different output devices, operating environments, and operating systems. Version 1.9.1 of the specification contains the latest updates introduced by Microsoft Office Word 2007. RTF uses the American National Standards Institute (ANSI), PC-8, Macintosh, or IBM PC character set to control the representation and formatting of a document, both on the screen and in print. With the RTF specification, documents created under different operating systems and with different software applications can be transferred between those operating systems and applications.


Why? Because I know I'll need this one day (I'm in RTF hell right now and well... it's not fun... :/  )

As an interesting side note look at the file sizes for the Doc and DocX. The DocX is 1/10th the size of the Doc (1 MB vs 11.9 MB). Why move to the new format? Fighting file size bloating could be one reason [insert joke about bloated feeling here]. How many Doc's are there on your machine and network? About a zillion? hum....


Related Past Post XRef:
RTF 1.9 Specification (Word 2007)