Any .Net utility to covert HTML to RTF while maintaining CSS?

落爺英雄遲暮 提交于 2019-12-12 04:05:26

问题


Is there any .Net utility out there that will convert HTML to RTF, which will also honour CSS styles? I've found a lot of tripe that will either strip all the styles away, or do a terrible job of presenting them.

There are plenty of HTML to PDF converters out there that do a decent job. I'm surprised it's so difficult to find something to go HTML to RTF.

Please don't reply if you represent sautinsoft. That product falls into the 'terrible' category.


回答1:


One option is to load a webbrowser with the html, select all, copy and paste into a richtextbox. Then use its RTF property.

var webBrowser = new WebBrowser();
webBrowser.Navigate("about:blank");
webBrowser.Document.Write("... html...");
webBrowser.Document.ExecCommand("SelectAll", false, null);
webBrowser.Document.ExecCommand("Copy", false, null);
richTextBox1.Paste();

It's better to use richtextbox v5.

If it's not accurate enough you can use word interop and then paste and copy from a temp word document. I can paste that code from one of my apps if you need it.



来源:https://stackoverflow.com/questions/17543744/any-net-utility-to-covert-html-to-rtf-while-maintaining-css

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