6

What is the best solution for converting RichTextFormat info to HTML in C#?

I know there are libraries out there that do this, and I was curious to see if you guys had any advice as to which ones are the better ones.

Thanks, Jeff

Charles Stewart
  • 11,661
  • 4
  • 46
  • 85
Yttrium
  • 2,057
  • 7
  • 25
  • 28

3 Answers3

2

I recently used a RTF to HTML conRTverter that worked great, called DocFrac.

It can be used with a GUI to convert files, but it also is a DLL.

I converted over 400 RTF files to HTML in a few minutes so performance is good too. I used the GUI so I don't have the details on the DLL. According to the site the DLL works with .NET however.

DocFrac at SourceForge

Update: fixed link, because www.docfrac.net doesn't exist anymore.

Abel
  • 56,041
  • 24
  • 146
  • 247
Tony Peterson
  • 20,522
  • 15
  • 48
  • 66
1

Try to use this library RTF to HTML .Net. It supports RTF to HTML and text to HTML converting ways. Full version not free but there is a free trial.

This code maybe useful:

        SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();

        //specify some options
        r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.XHTML_10;
        r.Encoding = SautinSoft.RtfToHtml.eEncoding.UTF_8;

        string rtfFile = @"d:\test.rtf";
        string htmlFile = @"d:\test.html";
        string rtfString = null;
        ReadFromFile(rtfFile,ref rtfString);

        int i = r.ConvertStringToFile(rtfString,htmlFile);
        if (i == 0)
        {
            System.Console.WriteLine("Converted successfully!");
            System.Diagnostics.Process.Start(htmlFile);
        }
        else
            System.Console.WriteLine("Converting Error!");
    }

    public static int ReadFromFile(string fileName,ref string fileStr)
    {
        try
        {
            FileInfo fi = new FileInfo(fileName);
            StreamReader strmRead = fi.OpenText();
            fileStr = strmRead.ReadToEnd();
            strmRead.Close();
            return 0;
        }
        catch 
        {
            //error open file
            System.Console.WriteLine("Error in open file");
            return 1;
        }
    }
Marry
  • 11
  • 1
0

ScroogeXHTML, a small library for RTF to HTML / XHTML conversion, might be useful. However it only supports a subset of the RTF standard. For reports with tables and other advanced layout, there are other libraries like the Logictran R2Net converter.

mjn
  • 36,362
  • 28
  • 176
  • 378