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

旧巷老猫 提交于 2019-12-21 12:22:10

问题


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


回答1:


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.




回答2:


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;
        }
    }



回答3:


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.



来源:https://stackoverflow.com/questions/518646/what-is-the-best-solution-for-converting-richtextformat-info-to-html-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!