我已经成功使用 WebBrowser
和 RichTextBox
做到了相反的操作。
但是,我如何将 RTF 转换为 HTML?
RtfPipe
;您可以直接在此安装,或通过包管理器控制台安装:Install-Package RtfPipe
然后在你的C#代码中,你可以非常容易地将RTF转换为HTML:
var html = RtfPipe.Rtf.ToHtml(rtf);
声明:我在这家公司工作。
我看到这个问题很久了,但也许有人正在寻找解决方案。我们的 RTF to HTML 组件可以将 RTF 转换为 HTML。您可以下载组件或尝试在线演示。如果您有疑问,请先尝试试用版。:) 试用版是免费的。
以下是在 ASP.NET 中从 RTF 转换为 HTML 的代码示例:
SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.HTML_401;
r.ImageStyle.IncludeImageInHtml = false; //To save images inside HTML as binary data specify this property to 'true'
r.ImageStyle.ImageFolder = Server.MapPath("");
r.ImageStyle.ImageSubFolder = "images";
r.ImageStyle.ImageFileName = "picture";
string rtf = ".....";
string html = r.ConvertString(rtf);
//show HTML
if (html.Length>0)
{
Response.Buffer = true;
Response.Clear();
Response.ContentType = "text/html";
Response.Write(html);
Response.Flush();
Response.End();
}