Hi
We have a requirement to know the rectangle bounding paragraph when word document is laid out. We need some clarifications on below points:
- Is it possible for a paragraph to span across multiple pages?
- 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?
Thanks
Manisha
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.
LayoutInfoWriter.run(it);
static class LayoutInfoWriter
{
public static void run(LayoutEnumerator it) throws Exception
{
displayLayoutElements(it, "");
}
///
/// 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
{
do
{
displayEntityInfo(it, padding);
if (it.moveFirstChild())
{
// Recurse into this child element.
displayLayoutElements(it, addPadding(padding));
it.moveParent();
}
} while (it.moveNext());
}
///
/// 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());
if (it.getType() == LayoutEntityType.SPAN)
System.out.print(" - " + it.getText());
System.out.println();
}
///
/// Returns a string of spaces for padding purposes.
///
private static String addPadding(String padding)
{
return padding + new String(" ");
}
}