Rtf to Html removes the html tables
Asked Answered
C

1

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.

Courtroom answered 10/2, 2017 at 14:51 Comment(4)
code.msdn.microsoft.com/windowsapps/… try this outPromotive
@AshishBahl No any HTML tables are removedCourtroom
can you share your code snippet?Promotive
@AshishBahl For the SautinSoft code? I just downloaded the test project from your link and replaced the rtf file with my own. And then had to download the dll from their site.Courtroom
J
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.

Jaclin answered 15/2, 2017 at 4:16 Comment(2)
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.Courtroom
Also note that this doesn't seem to work, please don't post a suggestion but an actual answer.Courtroom

© 2022 - 2024 — McMap. All rights reserved.