We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Preserving Rich Text With GetText or ToText

I have C# method that reads a Word document, performs some manipulation on the content, then should return a string that will be loaded into a Rich Text editor on a web page (we are using CK Editor). My problem is that any rich text formatting, i.e. bold, underline, etc., is not preserved.

Is there a method which will etract the content of a document into a string and preserve all of the rich text tags?


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Maybe in your case, you should convert your document to HTML. Please see the following code:

public string ConvertDocumentToHtml(Document doc)


string html = string.Empty;

// Save docuemnt to MemoryStream in Hml format

using (MemoryStream htmlStream = new MemoryStream())


doc.Save(htmlStream, SaveFormat.Html);

// Get Html string

html = Encoding.UTF8.GetString(htmlStream.GetBuffer(), 0, (int)htmlStream.Length);


// There could be BOM at the beggining of the string.

// We should remove it from the string.

while (html[0]!='<')

html = html.Substring(1);

return html;


Hope this helps. Please let me know if you need more assistance, I will be glad to help you.

Best regards.

This works! Thanks again Alexey!