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

Free Support Forum - aspose.com

How can an embedded file be converted to Pdf?

Hi,
How can I convert an embedded file in MS Word and PPT to pdf ?

I am using Java Aspose 2.7.0.

Hello
Thanks for your inquiry. Could you please attach your input document here? I will investigate it and provide you more information.
Best regards,

Attaching the file.
Main file contains the Embedded file as a link inside the Main file.

Hello
Thank you for additional information. Actually there are no any embedded documents inside the attached document. There is just a linked document. In this case you can just take this linked document and convert directly to PDF using Aspose.Words.
Best regards,

The files can be embedded by providing a link or a icon . So, how can I get the details about the embedded files while converting the main file to pdf.

Hello
Thanks for your inquiry. Please see the attached document. There are three embedded objects inside the attached document. Simple embedded document, embedded as link and embedded as icon (show icon). You can try using the following code to extract these embedded objects and convert them to PDF.

Document doc = new Document("C:\\Temp\\Test.docx");
// Get collection of shapes
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
int i = 0;
// Loop through all shapes
foreach(Shape shape in shapes)
{
    if (shape.OleFormat != null)
    {
        if (!shape.OleFormat.IsLink)
        {
            // Extract OLE object
            if (shape.OleFormat.ProgId == "Word.Document.12")
            {
                MemoryStream stream = new MemoryStream();
                shape.OleFormat.Save(stream);
                Document newDoc = new Document(stream);
                newDoc.Save(string.Format("C:\\Temp\\outEmbeded_{0}.pdf", i));
                i++;
            }
        }
        else
        {
            string filePath = shape.OleFormat.SourceFullName;
            Document newDoc = new Document(filePath);
            newDoc.Save(string.Format("C:\\Temp\\outLinkedEmbeded_{0}.pdf", i));
            i++;
        }
    }
}

Best regards,