Settings

RtfFormatProvider allows for import of RTF documents and respectively export of RadRichTextBox 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.
    • Null: When the FieldResultMode is set to null, fields' display mode is not changed. This can provide a better performance and lower memory usage while exporting.

    Example 1: Setting the ExportSettings of RtfFormatProvider

        RtfExportSettings exportSettings = new RtfExportSettings(); 
        exportSettings.ExportImagesInCompatibilityMode = true; 
        exportSettings.FieldResultMode = FieldDisplayMode.DisplayName; 
     
        RtfFormatProvider 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.

Example 2: Setup Default RtfFormatProvider

RtfFormatProvider rtfFormatProvider = DocumentFormatProvidersManager.GetProviderByExtension("rtf") as RtfFormatProvider; 
RtfImportSettings rtfImportSettings = new RtfImportSettings(); 
rtfImportSettings.FontSubstituting += rtfImportSettings_FontSubstituting; 
rtfFormatProvider.ImportSettings = rtfImportSettings; 
 
void rtfImportSettings_FontSubstituting(object sender, FontSubstitutingEventArgs e)  
{  
    if(e.OriginalFontName.Equals("Cambria")) 
    { 
        e.SubstitutionFontFamily = new FontFamily("Calibri"); 
    } 
} 

See Also

In this article