我有以下代码将 rtf 文本转换为 html:

private string RtfToHtml(string rtf)
{
    IRtfDocument rtfDocument = RtfInterpreterTool.BuildDoc(rtf);
    RtfHtmlConverter htmlConverter = new RtfHtmlConverter(rtfDocument);
    return htmlConverter.Convert();
}

这是取自 this library on code project.

如果我的 rtf 文本包含 Html 表,例如:
{\*\htmltag96 <table cellspacing="0" border="0" width="600">}\htmlrtf {\pard\plain \f0\fs24 \htmlrtf0

它们在生成的 html 文本中被删除。我怎样才能保存这些?

但是,表格中的任何文本或详细信息都会保留,这会导致 html 文本由于缺少表格而无法正确格式化。

最佳答案

在您从何处获取库的文章的介绍接近尾声时:

这个项目可能会有所帮助:
rtf2html
它声称可以比任何其他现有转换器更好地处理表格。但是,它是用 C++ 编写的,据我所知,您正在使用 C#。
既然如此,你可能想看看项目中的一些源代码,以帮助你用 C# 重写同样的东西。
至于可以正确处理表的现有 C# 库,我认为目前不存在。

关于c# - Rtf to Html 删除 html 表格,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42162258/

10-12 17:37
查看更多