You cannot just "copy" it. If you do, it won't work as format required by
RichTextBox
is RTF (
http://en.wikipedia.org/wiki/Rich_Text_Format[
^]). Those formats are completely different; and there are no exact one-to-one correspondence between notions of these two different mark-up languages. So, you only can interpret one format as another one using some mapping and mapping rules
you have to define.
In practice, however, you will probably deal with some HTML subset. Also, you can figure out reasonable rules in a pretty simple way: write some HTML code, copy it in browser and paste in
RichTextBox
(you can also use Wordpad.EXE); then compare the raw RTF results (use regular text viewer, not RTF-capable) with HTML source. Also use some RTF reference. After such research, you will have a pretty good idea of the mapping you want to have.
For RTF references, see:
http://msdn.microsoft.com/en-us/library/aa140284%28v=office.10%29.aspx[
^],
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=7105[
^],
http://www.biblioscape.com/rtf15_spec.htm[
^].
Now, you need to generate RTF using
System.Windows.Forms.WebBrowser
control with some HTML page loaded from some URL. I don't think you need to use
WebBrowser.DocumentStream
property, because… this is only a stream. You can use it, but now, when I hopefully ruined you hope for just copying a stream in a stream (sorry about that :-)), you should understand that you would need to parse its content anyway. Why? You would need to use some third-party HTML parser; they are available but… those are all hassles.
Instead, you can immediately use the instance of the DOM model for a currently load document using the property
WebBrowser.Document
. You can traverse all the element starting from this DOM Node and directly map all the children onto your RTF code
That will really do the trick.
Good luck,
—SA