Identify Logo and replace it from Word Document

source–> new1.docx (2.2 MB)

from this file I extract logo. search for logos in all other doucments and if found, it will be replaced with the extracted one.

target documents - > iamges.docx (327.9 KB)
labelled1.docx (25.6 KB)
new.docx (2.8 MB)
Reptiles.docx (755.3 KB)
new1.docx (2.9 MB)

@pooja.jayan Thank you for additional information. But unfortunately, I cannot reproduce the problem on my side. Size of the logo is correct in the output documents. Tested with all target documents you have attached.

In evey targeted documents, are you getting the same new logo, i mean does it have the same height and width?

sharing you a document with screenshots from documents i am getting on my end

output.docx (193.7 KB)

and the aspose.words package version I have used :
<PackageReference Include="Aspose.Words" Version="21.5.0" />

@pooja.jayan

Yes, in all output documents logo image have the same height and width.

I have used the latest 23.9 version for testing and here is the output document produced on my side when use labelled1.docx as destination document: out.docx (25.6 KB)

if I use labelled1.dpcx as the target document gettimg the logo in same height and width as of original logo.

But can u check on this file new1.docx (3.6 MB)
, if I use this particular document as target, logo dimension is different

@pooja.jayan Unfortunately, I still cannot reproduce the problem. I have used the following code to check logo shape dimensions in both source and destination documents before and after changing the logo image:

Document document = new Document(@"C:\Temp\src.docx");

// Get source logo shape.
Shape srcLogoShape = document.GetChildNodes(NodeType.Shape, true).Cast<Shape>()
    .Where(s => (s.Name == "logo" || s.AlternativeText == "logo" || s.Title == "logo")).FirstOrDefault();

// Print Logo dimensions in source document
Console.WriteLine($"Source - W:{srcLogoShape.Width}; H:{srcLogoShape.Height}");

Document newdoc = new Document(@"C:\Temp\dst.docx");
// Get destination logo shape.
Shape dstLogoShape = newdoc.GetChildNodes(NodeType.Shape, true).Cast<Shape>()
    .Where(s => (s.Name == "logo" || s.AlternativeText == "logo" || s.Title == "logo")).FirstOrDefault();

// Print Logo dimensions in dst document before changing it
Console.WriteLine($"Destination before - W:{dstLogoShape.Width}; H:{dstLogoShape.Height}");

dstLogoShape.AspectRatioLocked = false;
dstLogoShape.Width = srcLogoShape.Width;
dstLogoShape.Height = srcLogoShape.Height;
dstLogoShape.ImageData.ImageBytes = srcLogoShape.ImageData.ImageBytes;

// Print Logo dimensions in dst document after changing it
Console.WriteLine($"Destination after - W:{dstLogoShape.Width}; H:{dstLogoShape.Height}");

newdoc.Save(@"C:\Temp\out.docx");

Document roundtrip = new Document(@"C:\Temp\out.docx");
// Get destination logo shape.
Shape roundtripLogoShape = roundtrip.GetChildNodes(NodeType.Shape, true).Cast<Shape>()
    .Where(s => (s.Name == "logo" || s.AlternativeText == "logo" || s.Title == "logo")).FirstOrDefault();

// Print Logo dimensions in dst document after save/open output document
Console.WriteLine($"Destination after save/open - W:{roundtripLogoShape.Width}; H:{roundtripLogoShape.Height}");

Got it working now when I upgraded to new version ( 22.7.0). I think that issue was version specific. Since the license is not renewed, can not upgrade to the latest one.

I can upgrade only to 22.7.0. I think the issue is resolved in this version.

Thank you Alexey Noskov. I appreciate your quick response.

@pooja.jayan It is perfect that you managed to resolve the problem. Please feel free to ask in case of any issues. We will be glad to assist you.