New to Telerik UI for WinForms? Download free 30-day trial

Settings

RtfFormatProvider allows for import of RTF documents and respectively export of RadRichTextEditor to Rtf. Additionally, the import/export settings provide modification options. The current article outlines the available settings.

Export Settings

RtfFormatProvider exposes ExportSettings, which allow customization in how fields are exported. The __ExportSetting__s property is of type RtfExportSettings which have the following properties and events:

  • ExportImagesInCompatibilityMode: A property of type bool that gets or sets whether the images should be exported in compatibility mode. You can use this option when the document will be used in older readers.
  • ImageExporting: Handling this event allows you to change the bytes and the extension of the image before exporting it.
  • FieldResultMode: This property defines how the fields are exported in the RTF content. This property is an enumeration and it allows the following values:
    • Code: Shows all fields codes in the current document.
    • DisplayName: Show all fields names in the current document.
    • Result: Replace the merge fields in your document with actual data from your recipient list.

Setting the ExportSettings of the RtfFormatProvider

RtfExportSettings exportSettings = new RtfExportSettings();
exportSettings.ExportImagesInCompatibilityMode = true;
exportSettings.FieldResultMode = FieldDisplayMode.DisplayName;
RtfFormatProvider rtfFormatProvider = new RtfFormatProvider();
rtfFormatProvider.ExportSettings = exportSettings;

Dim exportSettings As RtfExportSettings = New RtfExportSettings()
exportSettings.ExportImagesInCompatibilityMode = True
exportSettings.FieldResultMode = FieldDisplayMode.DisplayName
Dim rtfFormatProvider As RtfFormatProvider = New RtfFormatProvider()
rtfFormatProvider.ExportSettings = exportSettings

Import Settings

Through the ImportSettings of RtfFormatProvider you can utilize the FontSubstituting event. This event allows you to handle the cases when the Rtf source specifies a Font that is not available to the RichTextBox. This is particularly useful in Silverlight when the Font can be resolved only if it is among the default ones when you do not want to rely on it being installed on the client machine. Example 4 shows how you can subscribe to the event and handle it.

Setup Default RtfFormatProvider

RtfFormatProvider rtfFormatProvider = DocumentFormatProvidersManager.GetProviderByExtension("rtf") as RtfFormatProvider;
RtfImportSettings rtfImportSettings = new RtfImportSettings();
rtfImportSettings.FontSubstituting += rtfImportSettings_FontSubstituting;
rtfFormatProvider.ImportSettings = rtfImportSettings;

Dim rtfFormatProvider As RtfFormatProvider = TryCast(DocumentFormatProvidersManager.GetProviderByExtension("rtf"), RtfFormatProvider)
Dim rtfImportSettings As RtfImportSettings = New RtfImportSettings()
AddHandler rtfImportSettings.FontSubstituting, AddressOf rtfImportSettings_FontSubstituting
rtfFormatProvider.ImportSettings = rtfImportSettings

FontSubstituting Event

private void rtfImportSettings_FontSubstituting(object sender, FontSubstitutingEventArgs e)
{   
    if (e.OriginalFontName.Equals("Cambria"))
    {
        e.SubstitutionFontFamily = new Telerik.WinControls.RichTextEditor.UI.FontFamily("Calibri");
    }
}

Private Sub rtfImportSettings_FontSubstituting(ByVal sender As Object, ByVal e As FontSubstitutingEventArgs)
    If e.OriginalFontName.Equals("Cambria") Then
        e.SubstitutionFontFamily = New Telerik.WinControls.RichTextEditor.UI.FontFamily("Calibri")
    End If
End Sub

See Also

In this article