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

3

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

Brunelle answered 6/2, 2009 at 0:32 Comment(0)
A
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.

Azarcon answered 6/2, 2009 at 1:34 Comment(0)
H
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;
        }
    }
Haul answered 23/11, 2011 at 8:48 Comment(0)
Y
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.

Yellowlegs answered 22/3, 2009 at 10:14 Comment(1)
This is spam. Relevant spam, to be sure, but still spam.Carburetor

© 2022 - 2024 — McMap. All rights reserved.