We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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


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!

@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);

Work perfect! Thank you very much

1 Like