Insert floating image

Hello,
I am using IReplacingCallback to insert images at specific locations in a Word document
Find and Replace in C#|Aspose.Words for .NET

Aspose.Words.ReplaceAction Aspose.Words.IReplacingCallback.Replacing(Aspose.Words.ReplacingArgs e)
{
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder((Aspose.Words.Document)e.MatchNode);
builder.MoveTo(e.MatchNode);
Aspose.Words.Drawing.Shape img = builder.InsertImage(imagefile);
return Aspose.Words.ReplaceAction.Replace;
}

This works fine, the image is placed at the start of the text that was found
But now I’d like to make the inline image a floating image.
I’ve tried adding :
shape.WrapType = Aspose.Words.Drawing.WrapType.None;
shape.BehindText = true;
but then the image is placed at the left of the page. The vertical position is correct though.

Is this a bug, or how can I accomplish correct horizontal positiong ?
I’ve tested this using Aspose.Words version 16.11

Thanks,
Edwin

Hi Edwin,


You can use Shape.Top and Shape.Left properties to adjust the position.

Hope, this helps.

Best regards,

Hello Awais,
That was my idea, but I can’t seem to retrieve the position of the text being searched.
How can I get the position of e.MatchNode ?

Thanks,
Edwin

Hi Edwin,


Thanks for your inquiry. You can achieve this using the Members/Properties of LayoutEnumerator class. Please also check LayoutCollector class. Hope, this helps.

Best regards,