RTF to HTML problem


I’m currently working with Aspose.Words to convert a RTF value to an HTML one.

As far as I’ve went, I’m currently having a strange issue with the dll.

My RTF value is stored in db when I load a Document with it and try to convert it to an HTML string, I’ve got something like this :

{\rtf1\deff0{\fonttbl{\f0 Times New Roman;}{\f1 Arial Narrow;}}{\colortbl\red0\green0\blue0 ;\red0\green0\blue255 ;}{*\listoverridetable}{\stylesheet {\ql\cf0 Normal;}{*\cs1\cf0 Default Paragraph Font;}{*\cs2\sbasedon1\cf0 Line Number;}{*\cs3\ul\cf1\ulc1 Hyperlink;}}\sectd\pard\plain\ql{\f1\fs18\cf0 1. Il est stipul\u233’e9 express\u233’e9ment que la … [rest of the rtf] …

The dll isn’t converting the rtf value, it just wrapped it inside some html tags.

But, when I take the rtf value, put in in a file, read it and give this Stream to load the document, everything works fine.

My problem is :

I have to read my rtf value from database and can’t create a temporary rtf file.

What can I do ?

Here is my code :

// this is the part that didn’t work, read from db
public static string FromRTFString(string rtf)
    var txt = string.Empty;
    using (var memoryStream = new MemoryStream())
        var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8);
        txt = RtfToHTML(memoryStream);
    return txt;

// this is the part that works, reads from file
private void Click(object sender, EventArgs e)
    using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "RTF files|*.rtf" })
        if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            var stream = new FileStream(ofd.FileName, FileMode.Open);

public static string RtfToHTML(Stream stream)
    var loadOptions = new LoadOptions() { LoadFormat = LoadFormat.Rtf };
    var doc = new Aspose.Words.Document(stream, loadOptions);
    return doc.ToString(SaveFormat.Html);

Thanks for your help !

Hi Pierre,

Thanks for your inquiry. Please use following code example to achieve your requirements. Hope this helps you. We suggest you please upgrade to the latest version of Aspose.Words for .NET 15.10.0.

If you still face problem, please share your input RTF string here for testing purposes. We will investigate the issue on our side and provide you more information.

private static Document RtfStringToDocument(string rtf)
    Document doc = null;
    // Convert RTF string to byte array.
    byte[] rtfBytes = Encoding.UTF8.GetBytes(rtf);
    // Create stream.
    using (MemoryStream rtfStream = new MemoryStream(rtfBytes))
        // Open document from stream.
        doc = new Document(rtfStream);
    return doc;
String strRTF = @"{\rtf1\........ }";
Document rtf = RtfStringToDocument(strRTF);
rtf.Save(MyDir + "Out.html");