13

I have the following code to convert rtf text to html:

private string RtfToHtml(string rtf)
{
    IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(rtf);
    RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument);
    return htmlConverter.Convert();
}

This is taken from this library on code project.

If my rtf text contains Html tables such as:

{\*\htmltag96 <table cellspacing="0" border="0" width="600">}\htmlrtf {\pard\plain \f0\fs24 \htmlrtf0 

They are removed in the resultant html text. How can I preserve these?

However, any text or details in the tables remains, this results in the html text not being formatted correctly because of the lack of tables.

TheLethalCoder
  • 6,668
  • 6
  • 34
  • 69

1 Answers1

3

Near the end of Introduction of the article from where you took the library :

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

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

This project might be helpful: rtf2html

It claims to process tables better than any other existing converter. However it is written in C++ and from what I can tell you are working with C#.

That being the case, you might want to take a look at some of the source code in the project in order to help you rewrite the same thing in C#.

As far as existing C# libraries that can properly process tables I don't think one currently exists.

Community
  • 1
  • 1
lax1089
  • 3,403
  • 3
  • 17
  • 37
  • Note that this converter is incredibly old and also doesn't support features such as images and hyperlinks. Also this is little more than a link only answer and would have been better posting as a comment like the previous commenter on the question has done. – TheLethalCoder Feb 15 '17 at 09:02
  • Also note that this doesn't seem to work, please don't post a suggestion but an actual answer. – TheLethalCoder Feb 21 '17 at 15:50