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

Free Support Forum - aspose.com

Rectangles bounding paragraph


We have a requirement to know the rectangle bounding paragraph when word document is laid out. We need some clarifications on below points:

1. Is it possible for a paragraph to span across multiple pages?
2. If it is possible for a paragraph to span across multiple pages, then how many rectangles do we get for that paragraph? Is it a rectangle for each page?

Hi Manisha,

Thanks for your inquiry. Yes, it is possible that a paragraph span across multiple pages. The Aspose.Words.Layout namespace provides classes that allow to access information such as on what page and where on a page particular document elements are positioned, when the document is formatted into pages.

We suggest you please read the member of LayoutEnumerator and LayoutCollector classes. A paragraph have one rectangle. LayoutEntityType.Line represents line of characters of text and inline objects. Line may have LayoutEntityType.Span child entities.

Could you please share some more detail about your query what exact you want to achieve using Aspose.Words? We will then provide you more information on this.

Please check following code example. Hope this helps you.

Document doc = new Document(getMyDir() + "in.docx");
// This creates an enumerator which is used to "walk" the elements of a rendered document.
LayoutEnumerator it = new LayoutEnumerator(doc);
// This sample uses the enumerator to write information about each layout element to the console.
static class LayoutInfoWriter
    public static void run(LayoutEnumerator it) throws Exception
        displayLayoutElements(it, "");
<font color="GREEN"><i>/// <summary>

/// Enumerates forward through each layout element in the document and prints out details of each element.
private static void displayLayoutElements(LayoutEnumerator it, String padding) throws Exception
displayEntityInfo(it, padding);

        <font color="RED"><b>if</b></font> <font color="BLUE"><b>(</b></font>it<font color="BLUE"><b>.</b></font>moveFirstChild<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>)</b></font>
        <font color="BLUE"><b>{</b></font>
            <font color="GREEN"><i>// Recurse into this child element.

displayLayoutElements(it, addPadding(padding));
} while (it.moveNext());

<font color="GREEN"><i>/// <summary>

/// Displays information about the current layout entity to the console.
private static void displayEntityInfo(LayoutEnumerator it, String padding) throws Exception
System.out.print(padding + it.getType() + " - " + it.getKind());

    <font color="RED"><b>if</b></font> <font color="BLUE"><b>(</b></font>it<font color="BLUE"><b>.</b></font>getType<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font> <font color="BLUE">=</font><font color="BLUE">=</font> LayoutEntityType<font color="BLUE"><b>.</b></font>SPAN<font color="BLUE"><b>)</b></font>
        System<font color="BLUE"><b>.</b></font>out<font color="BLUE"><b>.</b></font>print<font color="BLUE"><b>(</b></font><font color="PURPLE">" - "</font> <font color="BLUE">+</font> it<font color="BLUE"><b>.</b></font>getText<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>

    System<font color="BLUE"><b>.</b></font>out<font color="BLUE"><b>.</b></font>println<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
<font color="BLUE"><b>}</b></font>

<font color="GREEN"><i>/// <summary>

/// Returns a string of spaces for padding purposes.
private static String addPadding(String padding)
return padding + new String(" ");