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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With