Getting the layout rectangle for displayed comments

When recording the layout for paragraphs the LayoutEnumerator will provide the layout rectangle for each span in the paragraph. However, when looking at paragraphs within a comment entity the layout rectangle retrieves just the width. It looks like this:

X = -2147483.75
Y = 0
Width = valid value
Height = 0

Using CommentDisplayMode.ShowInBalloons, the TraverseLayoutForward sample code from LayoutEnumerator demonstrates this. Am I missing something?

Thanks.

@dave4

Summary
When CommentDisplayMode is set to ShowInBalloons, the comment text is rendered as a balloon that is drawn after the page layout is calculated. Because the balloon is not part of the layout tree, LayoutEnumerator (and LayoutCollector) cannot provide a full layout rectangle for the comment – only the width value is meaningful, while X, Y and Height are returned as placeholder values.

Why it happens

  • Balloon‑style comments are rendered by the visual layer, not by the layout engine, so they do not have a concrete rectangular area in the layout hierarchy.
  • The layout API therefore returns sentinel values (e.g., a large negative X and a height of 0) for the rectangle of a balloon comment.

What to do next

  1. Use the anchor paragraph’s rectangle – If you need to know where the balloon will be attached, retrieve the layout rectangle of the paragraph that the comment is anchored to (using LayoutCollector/LayoutEnumerator). This gives you the X, Y, Width and Height of the anchor.
  2. Switch to inline comment rendering – If a full rectangle for the comment itself is required, set the layout option to render comments inline:
doc.getLayoutOptions().setCommentDisplayMode(CommentDisplayMode.Inline);

In inline mode the comment becomes part of the normal flow and the layout API will return a proper rectangle.
3. If balloon comments must be kept – Approximate the visual bounds of the balloon by applying a fixed offset to the anchor paragraph’s rectangle, or design your UI to rely only on the anchor position.
4. Create a minimal reproducible example – Build a small document with a single comment, run the code in both ShowInBalloons and Inline modes, and compare the results. This can help verify the behaviour in your specific Aspose.Words version.

Note: The described behaviour is consistent with the way Aspose.Words handles balloon‑style comments; the layout API does not expose the balloon’s full geometry.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

1 Like

@dave4
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-28875

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Unfortunately, there is no CommentDisplayMode.Inline option, only:

namespace Aspose.Words.Layout
{
	//
	// Summary:
	//     Specifies the rendering mode for document comments.
	public enum CommentDisplayMode
	{
		Hide = 0,
		ShowInBalloons = 1,
		ShowInAnnotations = 2
	}
}

I see that there has been an issue created (WORDSNET-28875), so I assume I’ll need to revisit this in future.

Thanks.

@dave4 The code suggested by Professionalize.Discourse is Ai hallucination. We will keep you updated and let you know once the issue is resolved or we have more information for you.