Set and get how to render the RTF document to keep compatibility with old RTF readers. Default value: ModernRtfReaders.

Namespace:  SautinSoft
Assembly:  SautinSoft.HtmlToRtf (in SautinSoft.HtmlToRtf.dll) Version:


 C#  Visual Basic 
public HtmlToRtf..::.eRtfCompatibility RtfCompatibility { get; set; }
Public Property RtfCompatibility As HtmlToRtf..::.eRtfCompatibility


There are a lot of various RTF readers: MS Word, WordPad, RichTextBox for WinForms, RichTextBox for WPF.
Let us say, MS Word supports RTF with images stored in different formats: Jpeg, PNG, EMF.But RichTextBox for WinForms only support images stored as Bitmap.

Playing with this property, you may adjust the component for your RTF reader.
We recommend to use default (ModernRtfReaders) settings.


CopyConvert HTML to WPF RichTextBox in C# (XAML)
<Window x:Class="Convert_HTML_to_WPF_RichTextBox.MainWindow"
        Title="Convert HTML to WPF RichTextBox" Height="800" Width="1000">
            <RowDefinition Height="Auto"></RowDefinition>
        <RichTextBox Grid.Row="0" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="RtfControl" VerticalScrollBarVisibility="Visible"></RichTextBox>
        <StackPanel Grid.Row="1" HorizontalAlignment="Right">
            <Button Margin="2,10,10,10" Padding="5" Name="Start" Click="Start_Click">Convert HTML and Load to RichTextBox</Button>
CopyConvert HTML to WPF RichTextBox in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SautinSoft;
using System.IO;

namespace Convert_HTML_to_WPF_RichTextBox
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        public MainWindow()

        /// <summary>
        /// Converts HTML document to RTF format; Places this RTF in RichTextBox;
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Start_Click(object sender, RoutedEventArgs e)
            string htmlFile = @"..\..\sample.html";
            string rtfString = String.Empty;

            // Create an instance of the converter.
            SautinSoft.HtmlToRtf h = new HtmlToRtf();

            // Specify to generate RTF syntax compatible with RichTextBox.
            h.RtfCompatibility = HtmlToRtf.eRtfCompatibility.OldRtfReaders;

            // Convert HTML to RTF.            
            if (h.OpenHtml(htmlFile))
                using (MemoryStream msRtf = new MemoryStream())
                    // Convert HTML to RTF.
                    if (h.ToRtf(msRtf))
                        // Place the RTF into RichTextBox.
                        System.Windows.Documents.TextRange tr = new System.Windows.Documents.TextRange(
                           RtfControl.Document.ContentStart, RtfControl.Document.ContentEnd);
                        tr.Load(msRtf, DataFormats.Rtf);

CopyConvert HTML to WPF RichTextBox in VB.Net
Imports SautinSoft
Imports System.IO

Class MainWindow
    Private Sub Start_Click(sender As Object, e As RoutedEventArgs)
        Dim htmlFile As String = "..\..\sample.html"
        Dim rtfString As String = String.Empty

        ' Create an instance of the converter.
        Dim h As SautinSoft.HtmlToRtf = New HtmlToRtf()

        ' Specify to generate RTF syntax compatible with RichTextBox.
        h.RtfCompatibility = HtmlToRtf.eRtfCompatibility.OldRtfReaders

        ' Convert HTML to RTF.            
        If h.OpenHtml(htmlFile) Then
            Using msRtf As New MemoryStream()
                ' Convert HTML to RTF.
                If h.ToRtf(msRtf) Then
                    ' Place the RTF into RichTextBox.
                    Dim tr As New System.Windows.Documents.TextRange(RtfControl.Document.ContentStart, RtfControl.Document.ContentEnd)
                    tr.Load(msRtf, DataFormats.Rtf)
                End If
            End Using
        End If
    End Sub
End Class

See Also