在 C# 中将 RichTextFormat 信息转换为 HTML 的最佳解决方案是什么?
我知道那里有图书馆可以做到这一点,我很想知道你们是否对哪些图书馆更好有任何建议。
谢谢,杰夫
我最近使用了一个效果很好的 RTF 到 HTML 转换器,称为 DocFrac。
它可以与 GUI 一起使用来转换文件,但它也是一个 DLL。
我在几分钟内将 400 多个 RTF 文件转换为 HTML,因此性能也很好。我使用了 GUI,所以我没有关于 DLL 的详细信息。但是,根据该站点,DLL 可以与 .NET 一起使用。
更新:固定链接,因为 www.docfrac.net 不再存在。
尝试将此库 RTF 用于 HTML .Net。它支持 RTF 到 HTML 和文本到 HTML 的转换方式。完整版不是免费的,但有免费试用版。
此代码可能有用:
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;
}
}
ScroogeXHTML,一个用于 RTF 到 HTML / XHTML 转换的小型库,可能很有用。但是它只支持 RTF 标准的一个子集。对于带有表格和其他高级布局的报告,还有其他库,例如 Logictran R2Net 转换器。