Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rtf to Html removes the html tables

Tags:

html

c#

rtf

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.

like image 774
TheLethalCoder Avatar asked Feb 10 '17 14:02

TheLethalCoder


People also ask

Can RTF have tables?

Because RTF data file is human- readable, experienced programmers can write their own RTF document, including tables and graphs directly based on the RTF specification.


1 Answers

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.

like image 147
lax1089 Avatar answered Oct 07 '22 00:10

lax1089