问题
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