We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
创建一个网络浏览器。加载 html 内容。选择全部并从中复制。粘贴到 Richtextbox 中。然后你就得到了 RTF
现在 rtbTemp.RTF 已经从 HTML 转换成了 RTF。
Create a WebBrowser. Load it with the html content. Select all and copy from it. Paste into a richtextbox. Then you have the RTF
Now rtbTemp.RTF has the RTF converted from the HTML.
TL;DR: 如果可能,我建议使用
OpenXml
格式和HtmlToOpenXml
nuget 包。Microsoft Word COM
我并没有真正深入研究这个主题,因为我的用例是在服务器上使用该功能,这使得 COM 组件不是一个很好的选择。
< strong>XHTML2RTF
正如 @IAmTimCorey 提到的,您可以使用此 codeproject 库。
缺点是:
Windows 窗体 Web 浏览器
正如 @Jerry 提到的,您可以使用 Windows 窗体
WebBrowser
控件。缺点是:
不支持的功能包括:
del
元素)DevExpress
“Paul V”的代码示例”来自 devexpress 支持中心。 (03.02.2015)
或者您可以使用
RichEditDocumentServer
类型,如 此示例。未知实际支持什么。
缺点是:
不支持的功能包括:
del
元素)Sautinsoft
更多示例和配置选项请参见 此处 和 此处。
支持以下内容:
缺点是:
使用知识库:
DIY
如果您只想支持有限的功能,您可以编写自己的转换器。如果支持的功能集太大,我不会推荐这样做。 (Sautinsoft 声称已编写了 20,000 多行代码)。
我有一个小型示例项目,但在当前状态下仅用于教育目的。
OpenXml
如果 OpenXml 格式也适合您的用例,您可以使用 HtmlToOpenXml nuget 包。它是免费的,并且支持我测试过其他解决方案的所有功能。
该项目基于由 microsoft 提供的 Open Xml SDK,并且似乎处于活动状态。
TL;DR: I recommend using the
OpenXml
format and theHtmlToOpenXml
nuget package if possible.Microsoft Word COM
I haven't really searched much into this topic as a my use case is to use the functionality on a server which makes COM components not a great selection.
XHTML2RTF
As @IAmTimCorey mentioned you can use this codeproject library.
Disadvantages are:
Windows Forms Web Browser
As @Jerry mentioned you can use the Windows Forms
WebBrowser
control.Disadvantages are:
Not supported features include:
del
element)DevExpress
Code sample of "Paul V" from the devexpress support center. (03.02.2015)
Or you could use the
RichEditDocumentServer
type as shown in this example.Unknown what actually is supported.
Disadvantages are:
Not supported features include:
del
element)Sautinsoft
More examples and configuration options can be found here and here.
Supported is the following:
Disadvantages are:
Usage knowledgebase:
DIY
If you only wanted to support limited functionality you could write your own converter. I would not recommend this if the supported feature set is too large. (Sautinsoft claims to have written over 20'000 lines of code).
I have a small sample project here but is only for educational purposes in its current state.
OpenXml
If the OpenXml format is also ok for your use case you can use the HtmlToOpenXml nuget package. Its free and did support all features I've tested the other solutions against.
The project is based on the Open Xml SDK by microsoft and seems active.
ExpertsExchange 文章充其量是一篇糟糕的文章。基本上OP放弃了,因为他们无法给出一个好的答案。他们列出了 CodeProject 文章的链接 ( http://www.codeproject.com/KB/ HTML/XHTML2RTF.aspx )向您展示如何将 HTML 转换为 RTF,但它并不是真正的 .NET 解决方案。相反,这将是需要高度适应的东西。
根据我的经验,目前还没有一个好的开源转换器。所有的碎片似乎都在那里,但正在等待有人将它们整合在一起。然而,您问题的直接答案是目前还没有转换器。
The ExpertsExchange article is a poor one at best. Basically the OP gave up because they couldn't give a good answer. They list a link to the CodeProject article ( http://www.codeproject.com/KB/HTML/XHTML2RTF.aspx ) that shows you how to convert HTML to RTF but it isn't really a .NET solution. Instead, it would be something that would need to be highly adapted.
From my experience, there isn't a good open source converter out there. The pieces all seem to be there but it is waiting for someone to do the legwork of putting it all together. However, the immediate answer to your question is that there is not a converter already out there.
似乎有一个基于 WPF RichTextBox 的新开源解决方案。唯一需要注意的是它在核心中仅支持 STAThreaded 应用程序,并且为了在 ie ASP.net 中使用,您需要在 STAThread 中调用它(但在文章中有一个示例)。
对于在 VSTO 加载项中使用,这已被确认可以工作(即 Outlook RTFBody)
Nuget:
https://www.nuget.org/packages/MarkupConverter/
项目:
https://github.com/figuemon/MarkupConverter
写入:
https://code.msdn.microsoft.com/Converting- Between- RTF-和-aaa02a6e
There seems to be a new opensource solution based on a WPF RichTextBox. The only caveat is it in the core only supports STAThreaded applications and in order to use in a i.e. ASP.net you need to call it in a STAThread (but there is a sample for that in the writeup).
For use in VSTO add-ins this is confirmed to work (ie. Outlook RTFBody)
Nuget:
https://www.nuget.org/packages/MarkupConverter/
Project:
https://github.com/figuemon/MarkupConverter
Writeup:
https://code.msdn.microsoft.com/Converting-between-RTF-and-aaa02a6e