Replace Logo

Hi there,

We are using Aspose .NET API to replace a logo in word documents. It works for some, but it fails on others. Here is the code we are using.
Please find attached a document, for which the logo replacement does not work. Can you please suggest what needs to be changed for the code?.

Thanks,
Ratnakar

            Document wordDocument = new Document(originalFileName);
                HeaderFooterCollection headers = wordDocument.FirstSection.HeadersFooters;
                Boolean logoFound = false;
                foreach (HeaderFooter header in headers)
                {
                    if (header.HeaderFooterType == HeaderFooterType.HeaderFirst
                        || header.HeaderFooterType == HeaderFooterType.HeaderPrimary || header.HeaderFooterType ==
                        HeaderFooterType.HeaderEven)
                    {
                        Shape shape = (Shape)header.GetChild(NodeType.Shape, 0, true);
                        if (shape!=null && (shape.HasImage))
                        {
                            logoFound = true;
                            shape.ImageData.SetImage(headerLogo);
                           

                        }
                     
                    }
           }

aa.doc.zip (29.3 KB)

@rmalla1,

Thanks for your inquiry. After an initial test with latest version of Aspose.Words for .NET 18.5, we were unable to reproduce this issue on our end (please see 18.5-output.zip (31.8 KB)). We would suggest you please upgrade to the latest version of Aspose.Words for .NET. Please see the following links.

We used the following code on our end for testing:

Document doc = new Document(MyDir + @"aa (2)\aa.doc");
HeaderFooterCollection headers = doc.FirstSection.HeadersFooters;
Boolean logoFound = false;
foreach (HeaderFooter header in headers)
{
    if (header.HeaderFooterType == HeaderFooterType.HeaderFirst
        || header.HeaderFooterType == HeaderFooterType.HeaderPrimary || header.HeaderFooterType ==
        HeaderFooterType.HeaderEven)
    {
        Shape shape = (Shape)header.GetChild(NodeType.Shape, 0, true);
        if (shape != null && (shape.HasImage))
        {
            logoFound = true;
            shape.ImageData.SetImage(Image.FromFile(MyDir + "Aspose.Words.png"));
        }
    }
}
doc.Save(MyDir + @"aa (2)\18.5.docx");