Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert HTML to RTF (Rich Text) in .NET without paying for a component? [closed]

Is there a free third-party or .NET class that will convert HTML to RTF (for use in a rich-text enabled Windows Forms control)?

The "free" requirement comes from the fact that I'm only working on a prototype and can just load the BrowserControl and just render HTML if need be (even if it is slow) and that Developer Express is going to be releasing their own such control soon-ish.

I don't want to learn to write RTF by hand, and I already know HTML, so I figure this is the quickest way to get some demonstrable code out the door quickly.

like image 283
Josh Kodroff Avatar asked Sep 29 '08 19:09

Josh Kodroff


People also ask

Can you convert HTML to RTF?

Open our free HTML to RTF converter website. Click inside the file drop area to upload HTML file or drag & drop HTML file. Click on Convert button. Your HTML files will be uploaded and converted to RTF result format.


1 Answers

Actually there is a simple and free solution: use your browser, ok this is the trick I used:

var webBrowser = new WebBrowser(); webBrowser.CreateControl(); // only if needed webBrowser.DocumentText = *yourhtmlstring*; while (_webBrowser.DocumentText != *yourhtmlstring*)     Application.DoEvents(); webBrowser.Document.ExecCommand("SelectAll", false, null); webBrowser.Document.ExecCommand("Copy", false, null); *yourRichTextControl*.Paste();  

This could be slower than other methods but at least it's free and works!

like image 101
Spartaco Avatar answered Oct 07 '22 16:10

Spartaco