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
(34)
32,255 times
Add to favorites
7/26/2012
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Can I use the library to consume in a website
    1 Posts | Last post April 03, 2019
    • Hi Matthew,
      
      I am using Froala Editor in my website and allowing the user to input rich text. The froala editor gives the output as html which is being stored in the database. The same rendered to the UI without any issues as the browser can understand html.
      
      But, now the user wanted to export the content into excel. So, I need to embed the html into an excel cell and need to display it similar to how it display on the web page. Can I use this library to fulfill my requirement (or) please suggest me an approach to achieve the same. 
      
      Thanks in advance.
  • 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.
  • 555-555-0199@example.com
    1 Posts | Last post October 13, 2017
    • 555-555-0199@example.com
  • 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üller.com">www.müller.com</a>
      thanks
  • Great stuff!
    1 Posts | Last post June 27, 2017
    • I see you have created a Github repo: https://github.com/mmanela/MarkupConverter. 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") != 
      selectorId) 
      
      and
      
       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)
      
      Thanks...
      
      
      
      
      
  • 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.
      
      Thanks
  • Is This Samle available in vb.net ?
    1 Posts | Last post March 17, 2015
    • Hi ,
      I want to make sure if this "converting between RTF and HTML" sample has a vb.net version ??
1 - 10 of 33 Items