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: 7.1.4.17

Syntax

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

Remarks

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.

Examples

CopyConvert HTML to WPF RichTextBox in C# (XAML)
<Window x:Class="Convert_HTML_to_WPF_RichTextBox.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Convert_HTML_to_WPF_RichTextBox"
        mc:Ignorable="d"
        Title="Convert HTML to WPF RichTextBox" Height="800" Width="1000">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <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>
        </StackPanel>
    </Grid>
</Window>
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()
        {
            InitializeComponent();
        }

        /// <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