Available for: UI for ASP.NET AJAX | UI for ASP.NET MVC | UI for WPF | UI for WinForms

Using RtfFormatProvider

RtfFormatProvider makes it easy to import and export RadFlowDocument to/from RTF format, preserving the entire document structure and formatting.

All you have to do in order to use RtfFormatProvider is add references to the assemblies listed below:

  • Telerik.Windows.Documents.Core.dll
  • Telerik.Windows.Documents.Flow.dll

Import

In order to import an RTF document, you need to use the Import() method of RtfFormatProvider.

The code from Example 1 shows how to use RtfFormatProvider to import an RTF document from a file.

Example 1: Import document from a file

RtfFormatProvider provider = new RtfFormatProvider(); 
using (Stream input = File.OpenRead("Sample.rtf")) 
{ 
    RadFlowDocument document = provider.Import(input); 
} 

And here is how you can import a document from string containing the RTF document:

Example 2: Import document from a string

RtfFormatProvider provider = new RtfFormatProvider(); 
RadFlowDocument document = provider.Import(input); 

The resulting RadFlowDocument can be used like any code-generated document.

Export

In order to export a document to RTF, you need to use the Export() method of RtfFormatProvider.

Example 3 shows how to use RtfFormatProvider to export RadFlowDocument to a file.

Example 3: Export a document to a file

RtfFormatProvider provider = new RtfFormatProvider(); 
using (Stream output = File.Create("sample.rtf")) 
{ 
    RadFlowDocument document = CreateRadFlowDocument(); 
    provider.Export(document, output); 
} 

You can also export the document to a string and preserve it in a database.

Example 4: Export a document to a string

RtfFormatProvider provider = new RtfFormatProvider(); 
RadFlowDocument document = CreateRadFlowDocument(); 
string output = provider.Export(document); 

The resulting documents can be opened in any application that supports RTF documents.

In this article
Not finding the help you need? Improve this article