Skip to content

Convert RTF documents

manfredi.marceca edited this page Apr 7, 2026 · 2 revisions

RTF to DOCX

To convert an RTF document to DOCX install the DocSharp.Docx package (the RTF -> DOCX converter is included in the Docx package) and use the minimal RtfToDocxConverter:

var converter = new RtfToDocxConverter();
converter.Convert("input.rtf", "output.docx"); // supports file paths or streams

The same object can often return a WordprocessingDocument or a byte array if needed:

using var doc = converter.ToWordprocessingDocument("input.rtf");
// or
byte[] docxBytes = converter.ConvertToBytes("input.rtf");

Default encoding and code page

The default settings should work fine for most conformant RTF documents. However, you can use the DefaultEncoding and DefaultCodePage properties to control how unknown or legacy text encodings are interpreted. Examples:

// Example: set UTF-8 as default encoding
var converter = new RtfToDocxConverter()
{
	DefaultEncoding = System.Text.Encoding.UTF8
};
converter.Convert("input.rtf", "output.docx");

// Example: specify a default Windows code page (e.g. 1252) indipendently from system culture.
var converter2 = new RtfToDocxConverter()
{
	DefaultCodePage = 1252
};
converter2.Convert("input.rtf", "output.docx");

Clone this wiki locally