Aspose.Words - embedded files with linked images

Hi, I have a problem. The goal is to take different files like PDF or PPT, convert these files to docx documents and then embedd these files into a word document.

The convertion to docx goes fine, and I amd also able to add them into the word document as embedded files (OLE objects). But when I open the embedded file, instead of images I receive an error that says “The linked image cannot be displayed. The file may have been moved, renamed or deleted. Verify the link points to the correct file and location”.

I am not sure what to do. The code is very simple for this:


class Program
{
    static void Main(string[] args)
    {

        var fsPdf = File.ReadAllBytes(@"<path to pdf with linked images>");
        var docxBytes = ConvertPdfToDocx(fsPdf);
        File.WriteAllBytes(@"<path of converted pdf to docx file>", docxBytes);
        CreateFileWithEmbeddedFile(null);
        Console.Read();
    }

    private static void CreateFileWithEmbeddedFile(byte[] embedded)
    {
        var document = new Aspose.Words.Document();
        var builder = new DocumentBuilder(document);
        //var ms = new MemoryStream(embedded);
        builder.InsertOleObject(@"<path of converted pdf to docx file>", false, true, null);
        document.Save(@"<path of file that contains the coverted file as embedded file>");
    }

    private static byte[] ConvertPdfToDocx(byte[] docData)
    {
        using (var msDoc = new MemoryStream(docData))
        using (var msTmp = new MemoryStream())
        {
            var doc = new Aspose.Pdf.Document(msDoc);
            var saveOptions = new Aspose.Pdf.DocSaveOptions
            {
                Format = Aspose.Pdf.DocSaveOptions.DocFormat.DocX,
                ExtractOcrSublayerOnly = false,

            };

            doc.Save(msTmp, saveOptions);
            return msTmp.ToArray();
        }
    }
}

I use the 21.40 version.

Thanks. DIma :slight_smile:

@dimager

We suggest you please use the DocumentBuilder.InsertOleObject with correct ProgId. Hope this helps you.

If you still face problem, please attach the following resources here for testing:

  • Your input document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

here is the project that shows you exactly what I mean. I also added 3 files for example.
Aspose27052021.zip (1.5 MB)

@dimager

We have tested the scenario using the latest version of Aspose.Words and Aspose.PDF and have not found the shared issue with output DOCX. Please check the attached output DOCX. 21.5.docx (183.0 KB)