Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Writing Your Own RTF Converter

, 1 Aug 2013 CPOL
An article on how to write a custom RTF parser and converter.
rtfconverter_sourcecode.zip
RtfConverter_SourceCode
bin
Debug
Release
Itenso.Rtf.Converter.Html.dll
Itenso.Rtf.Converter.Xml.dll
Itenso.Rtf.Interpreter.dll
Itenso.Rtf.Parser.dll
Itenso.Sys.dll
log4net.dll
nunit-console-runner.dll
nunit.core.dll
nunit.framework.dll
nunit.util.dll
Rtf2Html.exe
Rtf2Raw.exe
Rtf2Xml.exe
RtfInterpreterTests.exe
RtfParserTests.exe
RtfWindows.exe
RtfWinForms.exe
Converter
Html
Properties
Xml
Properties
docu
Word2007RTFSpec9.pdf
ext
log4net.dll
nunit-console-runner.dll
nunit.core.dll
nunit.framework.dll
nunit.util.dll
Interpreter
Converter
Image
Text
Interpreter
Model
Properties
Support
InterpreterTests
Properties
RtfInterpreterTest
RtfInterpreterTest_0.rtf
RtfInterpreterTest_1.rtf
RtfInterpreterTest_10.rtf
RtfInterpreterTest_11.rtf
RtfInterpreterTest_12.rtf
RtfInterpreterTest_13.rtf
RtfInterpreterTest_14.rtf
RtfInterpreterTest_15.rtf
RtfInterpreterTest_16.rtf
RtfInterpreterTest_17.rtf
RtfInterpreterTest_18.rtf
RtfInterpreterTest_19.rtf
RtfInterpreterTest_2.rtf
RtfInterpreterTest_20.rtf
RtfInterpreterTest_21.rtf
RtfInterpreterTest_22.rtf
RtfInterpreterTest_23.rtf
RtfInterpreterTest_3.rtf
RtfInterpreterTest_4.rtf
RtfInterpreterTest_4.rtf.jpg
RtfInterpreterTest_4.rtf.jpg.hex
RtfInterpreterTest_5.rtf
RtfInterpreterTest_5.rtf.png
RtfInterpreterTest_5.rtf.png.hex
RtfInterpreterTest_6.rtf
RtfInterpreterTest_6.rtf.wmf
RtfInterpreterTest_6.rtf.wmf.hex
RtfInterpreterTest_7.rtf
RtfInterpreterTest_7.rtf.emf
RtfInterpreterTest_7.rtf.emf.hex
RtfInterpreterTest_8.rtf
RtfInterpreterTest_8.rtf.wmf
RtfInterpreterTest_8.rtf.wmf.hex
RtfInterpreterTest_9.rtf
RtfInterpreterTest_fail_0.rtf
RtfInterpreterTest_fail_1.rtf
RtfInterpreterTest_fail_2.rtf
RtfInterpreterTest_fail_3.rtf
RtfInterpreterTest_fail_4.rtf
keys
ItensoRtfConverter.snk
Parser
Model
Parser
Properties
Support
ParserTests
Properties
RtfParserTest
minimal.rtf
RtfParserTest_0.rtf
RtfParserTest_1.rtf
RtfParserTest_2.rtf
RtfParserTest_3.rtf
RtfParserTest_4.rtf
RtfParserTest_5.rtf
RtfParserTest_6.rtf
RtfParserTest_7.rtf
RtfParserTest_8.rtf
RtfParserTest_fail_0.rtf
RtfParserTest_fail_1.rtf
RtfParserTest_fail_2.rtf
RtfParserTest_fail_3.rtf
RtfParserTest_fail_4.rtf
RtfParserTest_fail_5.rtf
RtfParserTest_fail_6.rtf
Rtf2Html
Properties
Rtf2Raw
Properties
Rtf2Xml
Properties
RtfWindows
Properties
RtfWinForms
DefaultText.rtf
Properties
Sys
Application
Collection
Logging
Properties
Test
RtfConverter_v1.7.0.zip
Rtf2Xml
Properties
bin
Release
Itenso.Rtf.Converter.Html.dll
Itenso.Rtf.Converter.Xml.dll
Itenso.Rtf.Interpreter.dll
Itenso.Rtf.Parser.dll
Itenso.Sys.dll
log4net.dll
nunit-console-runner.dll
nunit.core.dll
nunit.framework.dll
nunit.util.dll
Rtf2Html.exe
Rtf2Raw.exe
Rtf2Xml.exe
RtfInterpreterTests.exe
RtfParserTests.exe
RtfWindows.exe
RtfWinForms.exe
Converter
Html
Properties
Xml
Properties
docu
Word2007RTFSpec9.pdf
ext
log4net.dll
nunit-console-runner.dll
nunit.core.dll
nunit.framework.dll
nunit.util.dll
Interpreter
Converter
Image
Text
Interpreter
Model
Properties
Support
InterpreterTests
Properties
RtfInterpreterTest
RtfInterpreterTest_0.rtf
RtfInterpreterTest_1.rtf
RtfInterpreterTest_10.rtf
RtfInterpreterTest_11.rtf
RtfInterpreterTest_12.rtf
RtfInterpreterTest_13.rtf
RtfInterpreterTest_14.rtf
RtfInterpreterTest_15.rtf
RtfInterpreterTest_16.rtf
RtfInterpreterTest_17.rtf
RtfInterpreterTest_18.rtf
RtfInterpreterTest_19.rtf
RtfInterpreterTest_2.rtf
RtfInterpreterTest_20.rtf
RtfInterpreterTest_21.rtf
RtfInterpreterTest_22.rtf
RtfInterpreterTest_23.rtf
RtfInterpreterTest_3.rtf
RtfInterpreterTest_4.rtf
RtfInterpreterTest_4.rtf.jpg
RtfInterpreterTest_4.rtf.jpg.hex
RtfInterpreterTest_5.rtf
RtfInterpreterTest_5.rtf.png
RtfInterpreterTest_5.rtf.png.hex
RtfInterpreterTest_6.rtf
RtfInterpreterTest_6.rtf.wmf
RtfInterpreterTest_6.rtf.wmf.hex
RtfInterpreterTest_7.rtf
RtfInterpreterTest_7.rtf.emf
RtfInterpreterTest_7.rtf.emf.hex
RtfInterpreterTest_8.rtf
RtfInterpreterTest_8.rtf.wmf
RtfInterpreterTest_8.rtf.wmf.hex
RtfInterpreterTest_9.rtf
RtfInterpreterTest_fail_0.rtf
RtfInterpreterTest_fail_1.rtf
RtfInterpreterTest_fail_2.rtf
RtfInterpreterTest_fail_3.rtf
RtfInterpreterTest_fail_4.rtf
keys
ItensoRtfConverter.snk
Parser
Model
Parser
Properties
Support
ParserTests
Properties
RtfParserTest
minimal.rtf
RtfParserTest_0.rtf
RtfParserTest_1.rtf
RtfParserTest_2.rtf
RtfParserTest_3.rtf
RtfParserTest_4.rtf
RtfParserTest_5.rtf
RtfParserTest_6.rtf
RtfParserTest_7.rtf
RtfParserTest_8.rtf
RtfParserTest_fail_0.rtf
RtfParserTest_fail_1.rtf
RtfParserTest_fail_2.rtf
RtfParserTest_fail_3.rtf
RtfParserTest_fail_4.rtf
RtfParserTest_fail_5.rtf
RtfParserTest_fail_6.rtf
Rtf2Html
Properties
Rtf2Raw
Properties
RtfWindows
Properties
RtfWinForms
DefaultText.rtf
Properties
Sys
Application
Collection
Logging
Properties
Test
Rtf2Html2010.suo
Rtf2Raw2010.suo
Rtf2Xml2010.suo
RtfInterpreter2010.suo
RtfParser2010.suo
RtfWindows2010.suo
RtfWinForms2010.suo
// -- FILE ------------------------------------------------------------------
// name       : RtfTextConvertSettings.cs
// project    : RTF Framelet
// created    : Jani Giannoudis - 2008.05.29
// language   : c#
// environment: .NET 2.0
// copyright  : (c) 2004-2010 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System;

namespace Itenso.Rtf.Converter.Text
{

	// ------------------------------------------------------------------------
	public class RtfTextConvertSettings
	{

		// ----------------------------------------------------------------------
		public const string SeparatorCr = "\r";
		public const string SeparatorLf = "\n";
		public const string SeparatorCrLf = "\r\n";
		public const string SeparatorLfCr = "\n\r";

		// ----------------------------------------------------------------------
		public RtfTextConvertSettings()
			: this( SeparatorCrLf )
		{
		} // RtfTextConvertSettings

		// ----------------------------------------------------------------------
		public RtfTextConvertSettings( string breakText )
		{
			SetBreakText( breakText );
		} // RtfTextConvertSettings

		// ----------------------------------------------------------------------
		public bool IsShowHiddenText
		{
			get { return showHiddenText; }
			set { showHiddenText = value; }
		} // IsShowHiddenText

		// ----------------------------------------------------------------------
		public string TabulatorText
		{
			get { return tabulatorText; }
			set { tabulatorText = value; }
		} // TabulatorText

		// ----------------------------------------------------------------------
		public string NonBreakingSpaceText
		{
			get { return nonBreakingSpaceText; }
			set { nonBreakingSpaceText = value; }
		} // NonBreakingSpaceText

		// ----------------------------------------------------------------------
		public string EmSpaceText
		{
			get { return emSpaceText; }
			set { emSpaceText = value; }
		} // EmSpaceText

		// ----------------------------------------------------------------------
		public string EnSpaceText
		{
			get { return enSpaceText; }
			set { enSpaceText = value; }
		} // EnSpaceText

		// ----------------------------------------------------------------------
		public string QmSpaceText
		{
			get { return qmSpaceText; }
			set { qmSpaceText = value; }
		} // QmSpaceText

		// ----------------------------------------------------------------------
		public string EmDashText
		{
			get { return emDashText; }
			set { emDashText = value; }
		} // EmDashText

		// ----------------------------------------------------------------------
		public string EnDashText
		{
			get { return enDashText; }
			set { enDashText = value; }
		} // EnDashText

		// ----------------------------------------------------------------------
		public string OptionalHyphenText
		{
			get { return optionalHyphenText; }
			set { optionalHyphenText = value; }
		} // OptionalHyphenText

		// ----------------------------------------------------------------------
		public string NonBreakingHyphenText
		{
			get { return nonBreakingHyphenText; }
			set { nonBreakingHyphenText = value; }
		} // NonBreakingHyphenText

		// ----------------------------------------------------------------------
		public string BulletText
		{
			get { return bulletText; }
			set { bulletText = value; }
		} // BulletText

		// ----------------------------------------------------------------------
		public string LeftSingleQuoteText
		{
			get { return leftSingleQuoteText; }
			set { leftSingleQuoteText = value; }
		} // LeftSingleQuoteText

		// ----------------------------------------------------------------------
		public string RightSingleQuoteText
		{
			get { return rightSingleQuoteText; }
			set { rightSingleQuoteText = value; }
		} // RightSingleQuoteText

		// ----------------------------------------------------------------------
		public string LeftDoubleQuoteText
		{
			get { return leftDoubleQuoteText; }
			set { leftDoubleQuoteText = value; }
		} // LeftDoubleQuoteText

		// ----------------------------------------------------------------------
		public string RightDoubleQuoteText
		{
			get { return rightDoubleQuoteText; }
			set { rightDoubleQuoteText = value; }
		} // RightDoubleQuoteText

		// ----------------------------------------------------------------------
		public string UnknownSpecialCharText
		{
			get { return unknownSpecialCharText; }
			set { unknownSpecialCharText = value; }
		} // UnknownSpecialCharText

		// ----------------------------------------------------------------------
		public string LineBreakText
		{
			get { return lineBreakText; }
			set { lineBreakText = value; }
		} // LineBreakText

		// ----------------------------------------------------------------------
		public string PageBreakText
		{
			get { return pageBreakText; }
			set { pageBreakText = value; }
		} // PageBreakText

		// ----------------------------------------------------------------------
		public string ParagraphBreakText
		{
			get { return paragraphBreakText; }
			set { paragraphBreakText = value; }
		} // ParagraphBreakText

		// ----------------------------------------------------------------------
		public string SectionBreakText
		{
			get { return sectionBreakText; }
			set { sectionBreakText = value; }
		} // SectionBreakText

		// ----------------------------------------------------------------------
		public string UnknownBreakText
		{
			get { return unknownBreakText; }
			set { unknownBreakText = value; }
		} // UnknownBreakText

		// ----------------------------------------------------------------------
		public string ImageFormatText
		{
			get { return imageFormatText; }
			set { imageFormatText = value; }
		} // ImageFormatText

		// ----------------------------------------------------------------------
		public void SetBreakText( string breakText )
		{
			if ( breakText == null )
			{
				throw new ArgumentNullException( "breakText" );
			}

			lineBreakText = breakText;
			pageBreakText = breakText + breakText;
			paragraphBreakText = breakText;
			sectionBreakText = breakText + breakText;
			unknownBreakText = breakText;
		} // SetBreakText

		// ----------------------------------------------------------------------
		// members: hidden text
		private bool showHiddenText;

		// members: special chars
		private string tabulatorText = "\t";
		private string nonBreakingSpaceText = " ";
		private string emSpaceText = " ";
		private string enSpaceText = " ";
		private string qmSpaceText = " ";
		private string emDashText = "-";
		private string enDashText = "-";
		private string optionalHyphenText = "-";
		private string nonBreakingHyphenText = "-";
		private string bulletText = "°";
		private string leftSingleQuoteText = "`";
		private string rightSingleQuoteText = "´";
		private string leftDoubleQuoteText = "``";
		private string rightDoubleQuoteText = "´´";
		private string unknownSpecialCharText;

		// members: breaks
		private string lineBreakText;
		private string pageBreakText;
		private string paragraphBreakText;
		private string sectionBreakText;
		private string unknownBreakText;

		// members: image
		private string imageFormatText = Strings.ImageFormatText;

	} // class RtfTextConvertSettings

} // namespace Itenso.Rtf.Converter.Text
// -- EOF -------------------------------------------------------------------

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jani Giannoudis
Software Developer (Senior)
Switzerland Switzerland
Jani is Co-founder of Meerazo.com, a free service which allows to share resources like locations, things, persons and their services in a cooperating group of people.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 1 Aug 2013
Article Copyright 2008 by Jani Giannoudis
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid