Free Support Forum - aspose.com

Convert Word doc to RTF in memory

I have a word document that I want to convert to RTF in memory.



So my sample code is like this:



Document doc = new Document(filepath);



string RTF = doc.ConvertToRTF();



or something similar.



I know I can save to disk or stream as RTF format and the convert but is there a easier way?



Hi Nitin,


Thanks for your inquiry. Please use the following code snippet for your requirement. Hope this helps you. Please let us know if you have any more queries.

<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;color:#2B91AF;mso-font-kerning:
0pt;mso-no-proof:yes”>Document<span lang=“EN-GB” style=“font-size:10.0pt;
font-family:“Courier New”;mso-font-kerning:0pt;mso-no-proof:yes”> doc = new Document(MyDir

  • “in.docx”);<o:p></o:p>

// Save document to stream as RTF

MemoryStream rtfStream = new MemoryStream();

SaveOptions options = SaveOptions.CreateSaveOptions(SaveFormat.Rtf);

doc.Save(rtfStream, options);

rtfStream.Position = 0;

StreamReader reader = new StreamReader(rtfStream);

string text = reader.ReadToEnd();

reader.Close();

that’s perfect! Thank you!

Hi Nitin,


Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.