RTF Conversions in Word Library
24 Jul 20265 minutes to read
RTF
The Rich Text Format (RTF) is one of the document formats supported by Microsoft Word and many other Word processing applications. RTF is a human-readable file format designed to interchange formatted text between applications. It is an optional format for Word that retains most formatting and all content of the original document.
Most word processors (including Microsoft Word) use XML-based file formats. Microsoft has discontinued enhancements to RTF but still supports it. The last version was 1.9.1, released in 2008.
To quickly start converting a Word document to RTF and vice versa, please check out this video:
Prerequisites
Assemblies and NuGet packages
Refer to the following links for assemblies and NuGet packages required based on platforms to convert an RTF document into a Word document and vice versa using the .NET Word Library (DocIO).
The Essential® DocIO converts the RTF document into Word document and vice versa. The following code shows how to convert RTF document into Word document.
NOTE
Refer to the appropriate tabs in the code snippets section: C# [Cross-platform] for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; C# [Windows-specific] for WinForms and WPF; VB.NET [Windows-specific] for VB.NET applications.
FileStream fileStreamPath = new FileStream("Input.rtf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//Opens an existing document from file system through constructor of WordDocument class
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Rtf))
{
//Saves the Word document to MemoryStream
MemoryStream stream = new MemoryStream();
document.Save(stream, FormatType.Docx);
//Closes the Word document
document.Close();
}//Loads an existing document
using (WordDocument document = new WordDocument("Input.rtf", FormatType.Rtf))
{
//Saves the Word document as DOCX file
document.Save("RtfToWord.docx", FormatType.Docx);
//Closes the document
document.Close();
}'Loads an existing document
Using document As New WordDocument("Input.rtf", FormatType.Rtf)
'Saves the Word document as DOCX file
document.Save("RtfToWord.docx", FormatType.Docx)
'Closes the document
document.Close()
End UsingYou can download a complete working sample from GitHub.
Convert Word to RTF
The following code example shows how to convert a Word document into an RTF document using the FormatType.Rtf save option.
FileStream fileStreamPath = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//Opens an existing document from file system through constructor of WordDocument class
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
//Saves the Word document to MemoryStream
MemoryStream stream = new MemoryStream();
document.Save(stream, FormatType.Rtf);
//Closes the Word document
document.Close();
}//Loads an existing document
using (WordDocument document = new WordDocument("Template.docx", FormatType.Docx))
{
//Saves the Word document as RTF file
document.Save("WordToRtf.rtf", FormatType.Rtf);
//Closes the document
document.Close();
}'Loads an existing document
Using document As New WordDocument("Template.docx", FormatType.Docx)
'Saves the Word document as RTF file
document.Save("WordToRtf.rtf", FormatType.Rtf)
'Closes the document
document.Close()
End UsingYou can download a complete working sample from GitHub.
Supported and Unsupported features
Refer to the following link for supported and unsupported features of DocIO by file format: Supported and Unsupported features.
Online Demo
- Explore the RTF to Word live demo to see how to convert an RTF file to a Word document using the .NET Word Library (DocIO).
- See the Word to RTF live demo to see how to convert a Word document to an RTF file using the .NET Word Library (DocIO).