Converting between RTF and HTML

This sample shows how to convert from HTML to RTF and from RTF to HTML. It makes use of the WPF RichTextBox to convert to XAML first and then to RTF or HTML.

C# (91.1 KB)
4.6 Star
31,819 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • How to run your sample in UWP app
    1 Posts | Last post March 09, 2019
    • Your code requires a single threaded apartment (STA). How we can run the code for RichEditBox control in UWP app? Could you please provide some sample code or guide lines? Thank you.
    1 Posts | Last post October 13, 2017
  • hyperlink with umlaut character
    1 Posts | Last post June 28, 2017
    • Html hyperlink conversion to rtf does not work with umlaut character
      e.g. <a href="http://www.mü">www.mü</a>
  • Great stuff!
    1 Posts | Last post June 27, 2017
    • I see you have created a Github repo: Awesome.
  • Found a little bug
    2 Posts | Last post May 19, 2017
    • In htmlcssparser.cs, method MatchSelectorLevel, the if statements:  
      if (selectorId != null && HtmlToXamlConverter.GetAttribute(xmlElement, "id") != 
       if (selectorClass != null && HtmlToXamlConverter.GetAttribute(xmlElement, "class") != selectorClass) 
                      return false; 
      Should convert the retrieved attribute to lowercase as you store css attributes in lowercase to _styleDefinitions. The bug results in css attributes not properly detected when named with capital letters.
      A possible fix would look like this:
      if (selectorId != null && (HtmlToModel.GetAttribute(xmlElement, "id")?? string.Empty).ToLower() != selectorId)
      if (selectorClass != null && (HtmlToModel.GetAttribute(xmlElement, "class")?? string.Empty).ToLower() != selectorClass)
    • eh.. I mean...
      A possible fix would look like this:
      if (selectorId != null && (HtmlToXamlConver.GetAttribute(xmlElement, "id")?? string.Empty).ToLower() != selectorId)
      if (selectorClass != null && (HtmlToXamlConver.GetAttribute(xmlElement, "class")?? string.Empty).ToLower() != selectorClass)
  • Error Converting RTF to HTML
    1 Posts | Last post July 08, 2016
    • While converting RTF to HTML I have bulleted list of 4 items in RTF. For 2 and 3 items I increased indent. But after conversion i am getting list inside a list instead of Indent. I am missing the indent when I do reverse conversion(HTML to RTF)
  • Is there a way to convert to VB.NET
    1 Posts | Last post January 12, 2016
    • I tried to use but I don't have C#, is there a way to have dll or in VB.NET ..?
      it's exactelly what I need to send a signature in email message because there is no way to send it in rtf format.. only HTML ...
      Thanks .. 
  • Windows Universal Version
    1 Posts | Last post May 14, 2015
    • I know this code is a few years old, but was curious if you had any plans on making a Windows Universal version of this code available.
  • Is This Samle available in ?
    1 Posts | Last post March 17, 2015
    • Hi ,
      I want to make sure if this "converting between RTF and HTML" sample has a version ??
  • Problem with \par
    1 Posts | Last post February 19, 2015
    • When I try to convert the following text...
      \par\parLet\rquotes get started!
      It just deletes "Let" giving only "'s get started"... I noticed the problem came from the XAML conversion. How can I fix that?
1 - 10 of 32 Items