Reading RTF File Containing an OLE Embedded Object

Question :

I need to read an RTF File that contains an OLE Object as innerdocument.

RTF File = [ Ole object (word document) is embedded into it.]

Sample RTF File that contains word as OLE Embedded into it.

Reference I have done :

  1. OLE as Image in RTF

Here they have done a program to extract the image embedded as OLE in RTF.

I had extracted the program which is marked as correct answer , but its does not work for me.

  1. Using OpenXML SDK. (it cannot be able to open RTF Files.)
  2. some other SDK like GemBox etc… Which cannot be able to open innerdocument ie. ole in RTF)

Work I have done :

I had done using microsoft.office.interop.word.dll which gives an accurate answer , but it will not work on server.

For eg: it opens an RTF File using MS WORD and which is installed in client machine where there is no WORD APPLICATION Installed in server.

so , this is not suitable for me.

I need to open and read the RTF OLE Content and i need to store in a string(say for eg). bcoz with string i can do lot of things.

Can anyone has an idea to solve my issue.?

Note : RTF File = [OLE File + RTF Header ]

So i made it as rtf file and opened.

Whether the content of the embedded ole object can be extracted using aspose library ?

@sivabalakrishnan

Thanks for your inquiry. Yes, you can achieve your requirement using Aspose.Words. Please use the following code example to extract the OLE object (Word document) from RTF and import it into Aspose.Words’ DOM to read its content. Hope this helps you.

Document doc = new Document(MyDir + "SAMPLE.rtf");

Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
if (shape.OleFormat != null)
{
    //Save the document to disk.
    shape.OleFormat.Save(MyDir + "output" + shape.OleFormat.SuggestedExtension);

    if (shape.OleFormat.SuggestedExtension == ".docx")
    {
        //Import the .docx ole object into Aspose.Words' DOM
        Document ole = new Document(MyDir + "output" + shape.OleFormat.SuggestedExtension);
        Console.WriteLine(ole.ToString(SaveFormat.Text));
    }
                    
}