Calculating height of a node in a tree

Dear Sir or Madam,

How can I calculate height of a node in a document? Eg. paragraph, table, row?

Regards,
Alex

@AlexanderNovickov,

Thanks for your inquiry. You can get the paragraph’s height using following code example.

Document doc = new Document(MyDir + "in.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

Paragraph paragraph = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);
enumerator.Current = collector.GetEntity(paragraph);
Console.WriteLine(enumerator.Rectangle.Height);

The height of a table row/cell is controlled using height and height rule properties. Please refer to the following article for more detail.
Specifying Row Heights

If you want to calculate table’s height using Aspose.Words.Layout API, we suggest you following solution.

  1. Insert the bookmark at the first cell of table.
  2. Insert another bookmark after the table.
  3. Use the Aspose.Words.Layout API to get the top position of bookmark. You can use LayoutEnumerator.Rectangle.Top.
  4. Use the same for second bookmark.
  5. At the end get the difference of two position to get the table’s height.

Please note that LayoutCollector.GetEntity method returns an opaque position of the LayoutEnumerator which corresponds to the specified node. This method works for only Paragraph nodes, as well as indivisible inline nodes, e.g. BookmarkStart or Shape. It doesn’t work for Run, CellRow or Table nodes, and nodes within header/footer.