Get absolute position of shape (top and left) inside a page

Hello,

I am trying to get the absolute position of shape (top and left) inside a page.
The shape is inside a table cell.
objShape.Top return 0
objShape.Left return 0
the objShape.RelativeHorizontalPosition value is “column”

In the Word object model i can do it using this code:

top = objShape.Range.Information[WdInformation.wdHorizontalPositionRelativeToPage];
left = objShape.Range.Information[WdInformation.wdVerticalPositionRelativeToPage];

Thank you very much!
Tomer

@TomerZa You can use LayoutCollector and LayoutEnumerator to get absolute position of the shape. For example see the following code:

Document doc = new Document(@"C:\Temp\in.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

// Get shape from the document.
Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

// Make sure shape is in the main body (LayoutCollector and LayoutEnumerator work only with nodes in the main body)
if (shape.GetAncestor(NodeType.HeaderFooter) == null)
{
    enumerator.Current = collector.GetEntity(shape);
    Console.WriteLine(enumerator.Rectangle);
}

Work perfect! Thank you very much

1 Like