com.aspose.words

Class LayoutEnumerator

  • java.lang.Object
    • com.aspose.words.LayoutEnumerator
public class LayoutEnumerator 
extends java.lang.Object

Enumerates page layout entities of a document. You can use this class to walk over the page layout model. Available properties are type, geometry, text and page index where entity is rendered, as well as overall structure and relationships. Use combination of LayoutCollector.getEntity(com.aspose.words.Node) and Current move to the entity which corresponds to a document node.

Example:

Demonstrates ways of traversing a document's layout entities.
public void layoutEnumerator() throws Exception {
    // Open a document that contains a variety of layout entities
    // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
    // They are defined visually by the rectangular space that they occupy in the document
    Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");

    // Create an enumerator that can traverse these entities
    LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
    Assert.assertEquals(doc, layoutEnumerator.getDocument());

    // The enumerator points to the first element on the first page and can be traversed like a tree
    layoutEnumerator.moveFirstChild();
    layoutEnumerator.moveFirstChild();
    layoutEnumerator.moveLastChild();
    layoutEnumerator.movePrevious();
    Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
    Assert.assertEquals("TTT", layoutEnumerator.getText());

    // Only spans can contain text
    layoutEnumerator.moveParent(LayoutEntityType.PAGE);
    Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());

    // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
    layoutEnumerator.reset();

    // "Visual order" means when moving through an entity's children that are broken across pages,
    // page layout takes precedence and we avoid elements in other pages and move to others on the same page
    System.out.println("Traversing from first to last, elements between pages separated:");
    traverseLayoutForward(layoutEnumerator, 1);

    // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
    System.out.println("Traversing from last to first, elements between pages separated:");
    traverseLayoutBackward(layoutEnumerator, 1);

    // "Logical order" means when moving through an entity's children that are broken across pages,
    // node relationships take precedence
    System.out.println("Traversing from first to last, elements between pages mixed:");
    traverseLayoutForwardLogical(layoutEnumerator, 1);

    System.out.println("Traversing from last to first, elements between pages mixed:");
    traverseLayoutBackwardLogical(layoutEnumerator, 1);
}

/// <summary>
/// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
/// </summary>
private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
    do {
        printCurrentEntity(layoutEnumerator, depth);

        if (layoutEnumerator.moveFirstChild()) {
            traverseLayoutForward(layoutEnumerator, depth + 1);
            layoutEnumerator.moveParent();
        }
    } while (layoutEnumerator.moveNext());
}

/// <summary>
/// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
/// </summary>
private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
    do {
        printCurrentEntity(layoutEnumerator, depth);

        if (layoutEnumerator.moveLastChild()) {
            traverseLayoutBackward(layoutEnumerator, depth + 1);
            layoutEnumerator.moveParent();
        }
    } while (layoutEnumerator.movePrevious());
}

/// <summary>
/// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
/// </summary>
private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
    do {
        printCurrentEntity(layoutEnumerator, depth);

        if (layoutEnumerator.moveFirstChild()) {
            traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
            layoutEnumerator.moveParent();
        }
    } while (layoutEnumerator.moveNextLogical());
}

/// <summary>
/// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
/// </summary>
private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
    do {
        printCurrentEntity(layoutEnumerator, depth);

        if (layoutEnumerator.moveLastChild()) {
            traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
            layoutEnumerator.moveParent();
        }
    } while (layoutEnumerator.movePreviousLogical());
}

/// <summary>
/// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
/// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
/// </summary>
private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
    String baseString = "\t";
    String tabs = StringUtils.repeat(baseString, indent);

    if (tabs.equals(layoutEnumerator.getKind())) {
        System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
    } else {
        System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
    }

    if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
        System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
    }

    Rectangle2D leRect = layoutEnumerator.getRectangle();
    System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
    System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
}

Constructor Summary
LayoutEnumerator(Document document)
Initializes new instance of this class.
 
Property Getters/Setters Summary
java.lang.ObjectgetCurrent()
void
setCurrent(java.lang.Objectvalue)
           Gets or sets current position in the page layout model. This property returns an opaque object which corresponds to the current layout entity.
DocumentgetDocument()
Gets document this instance enumerates.
java.lang.StringgetKind()
Gets the kind of the current entity. This can be an empty string but never null.
intgetPageIndex()
Gets the 1-based index of a page which contains the current entity.
java.awt.geom.Rectangle2D.FloatgetRectangle()
Returns the bounding rectangle of the current entity relative to the page top left corner (in points).
java.lang.StringgetText()
Gets text of the current span entity. Throws for other entity types.
intgetType()
Gets the type of the current entity. The value of the property is LayoutEntityType integer constant.
 
Method Summary
booleanmoveFirstChild()
Moves to the first child entity.
booleanmoveLastChild()
Moves to the last child entity.
booleanmoveNext()
Moves to the next sibling entity in visual order. When iterating lines of a paragraph broken across pages this method will not move to the next page but rather move to the next entity on the same page.
booleanmoveNextLogical()
Moves to the next sibling entity in a logical order. When iterating lines of a paragraph broken across pages this method will move to the next line even if it resides on another page.
booleanmoveParent()
Moves to the parent entity.
booleanmoveParent(int types)
Moves to the parent entity of the specified type.
booleanmovePrevious()
Moves to the previous sibling entity.
booleanmovePreviousLogical()
Moves to the previous sibling entity in a logical order. When iterating lines of a paragraph broken across pages this method will move to the previous line even if it resides on another page.
voidreset()
Moves the enumerator to the first page of the document.
 

    • Constructor Detail

      • LayoutEnumerator

        public LayoutEnumerator(Document document)
                         throws java.lang.Exception
        Initializes new instance of this class.

        If page layout model of the document hasn't been built the enumerator calls Document.updatePageLayout() to build it.

        Whenever document is updated and new page layout model is created, a new enumerator must be used to access it.

        Parameters:
        document - A document whose page layout model to enumerate.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
    • Property Getters/Setters Detail

      • getCurrent/setCurrent

        public java.lang.Object getCurrent() / public void setCurrent(java.lang.Object value)
        
        Gets or sets current position in the page layout model. This property returns an opaque object which corresponds to the current layout entity.

        Example:

        Shows how to see the page spans of nodes.
        // Open a blank document and create a DocumentBuilder
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Create a LayoutCollector object for our document that will have information about the nodes we placed
        LayoutCollector layoutCollector = new LayoutCollector(doc);
        
        // The document itself is a node that contains everything, which currently spans 0 pages
        Assert.assertEquals(layoutCollector.getDocument(), doc);
        Assert.assertEquals(layoutCollector.getNumPagesSpanned(doc), 0);
        
        // Populate the document with sections and page breaks
        builder.write("Section 1");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.insertBreak(BreakType.PAGE_BREAK);
        doc.appendChild(new Section(doc));
        doc.getLastSection().appendChild(new Body(doc));
        builder.moveToDocumentEnd();
        builder.write("Section 2");
        builder.insertBreak(BreakType.PAGE_BREAK);
        builder.insertBreak(BreakType.PAGE_BREAK);
        
        // The collected layout data won't automatically keep up with the real document contents
        Assert.assertEquals(layoutCollector.getNumPagesSpanned(doc), 0);
        
        // After we clear the layout collection and update it, the layout entity collection will be populated with up-to-date information about our nodes
        // The page span for the document now shows 5, which is what we would expect after placing 4 page breaks
        layoutCollector.clear();
        doc.updatePageLayout();
        Assert.assertEquals(layoutCollector.getNumPagesSpanned(doc), 5);
        
        // We can also see the start/end pages of any other node, and their overall page spans
        NodeCollection nodes = doc.getChildNodes(NodeType.ANY, true);
        for (Node node : (Iterable<Node>) nodes) {
            System.out.println(MessageFormat.format("->  NodeType.{0}:", node.getNodeType()));
            System.out.println(MessageFormat.format("\tStarts on page {0}, ends on page {1}, spanning {2} pages.", layoutCollector.getStartPageIndex(node), layoutCollector.getEndPageIndex(node), layoutCollector.getNumPagesSpanned(node)));
        }
        
        // We can iterate over the layout entities using a LayoutEnumerator
        LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
        Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
        // The LayoutEnumerator can traverse the collection of layout entities like a tree
        // We can also point it to any node's corresponding layout entity like this
        layoutEnumerator.setCurrent(layoutCollector.getEntity(doc.getChild(NodeType.PARAGRAPH, 1, true)));
        Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
        Assert.assertEquals("ΒΆ", layoutEnumerator.getText());
      • getDocument

        public Document getDocument()
        
        Gets document this instance enumerates.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • getKind

        public java.lang.String getKind()
        
        Gets the kind of the current entity. This can be an empty string but never null. This is a more specific type of the current entity, e.g. bookmark span has LayoutEntityType.SPAN type and may have either a BOOKMARKSTART or BOOKMARKEND kind.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • getPageIndex

        public int getPageIndex()
        
        Gets the 1-based index of a page which contains the current entity.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • getRectangle

        public java.awt.geom.Rectangle2D.Float getRectangle()
        
        Returns the bounding rectangle of the current entity relative to the page top left corner (in points).

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • getText

        public java.lang.String getText()
        
        Gets text of the current span entity. Throws for other entity types.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • getType

        public int getType()
        
        Gets the type of the current entity. The value of the property is LayoutEntityType integer constant.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
    • Method Detail

      • moveFirstChild

        public boolean moveFirstChild()
                              throws java.lang.Exception
        Moves to the first child entity.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • moveLastChild

        public boolean moveLastChild()
        Moves to the last child entity.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • moveNext

        public boolean moveNext()
                        throws java.lang.Exception
        Moves to the next sibling entity in visual order. When iterating lines of a paragraph broken across pages this method will not move to the next page but rather move to the next entity on the same page.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • moveNextLogical

        public boolean moveNextLogical()
        Moves to the next sibling entity in a logical order. When iterating lines of a paragraph broken across pages this method will move to the next line even if it resides on another page. Note that all LayoutEntityType.SPAN entities are linked together thus if Current entity is span repeated calling of this method will iterates complete story of the document.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • moveParent

        public boolean moveParent()
        Moves to the parent entity.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • moveParent

        public boolean moveParent(int types)
        Moves to the parent entity of the specified type. This method is useful if you need to find the cell, column or header/footer parent of the entity.
        Parameters:
        types - A LayoutEntityType value. The parent entity type to move to. Use bitwise-OR to specify multiple parent types.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • movePrevious

        public boolean movePrevious()
                            throws java.lang.Exception
        Moves to the previous sibling entity.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • movePreviousLogical

        public boolean movePreviousLogical()
        Moves to the previous sibling entity in a logical order. When iterating lines of a paragraph broken across pages this method will move to the previous line even if it resides on another page. Note that all LayoutEntityType.SPAN entities are linked together thus if Current entity is span repeated calling of this method will iterates complete story of the document.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }
      • reset

        public void reset()
                  throws java.lang.Exception
        Moves the enumerator to the first page of the document.

        Example:

        Demonstrates ways of traversing a document's layout entities.
        public void layoutEnumerator() throws Exception {
            // Open a document that contains a variety of layout entities
            // Layout entities are pages, cells, rows, lines and other objects included in the LayoutEntityType enum
            // They are defined visually by the rectangular space that they occupy in the document
            Document doc = new Document(getMyDir() + "Document.LayoutEntities.docx");
        
            // Create an enumerator that can traverse these entities
            LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
            Assert.assertEquals(doc, layoutEnumerator.getDocument());
        
            // The enumerator points to the first element on the first page and can be traversed like a tree
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveFirstChild();
            layoutEnumerator.moveLastChild();
            layoutEnumerator.movePrevious();
            Assert.assertEquals(LayoutEntityType.SPAN, layoutEnumerator.getType());
            Assert.assertEquals("TTT", layoutEnumerator.getText());
        
            // Only spans can contain text
            layoutEnumerator.moveParent(LayoutEntityType.PAGE);
            Assert.assertEquals(LayoutEntityType.PAGE, layoutEnumerator.getType());
        
            // We can call this method to make sure that the enumerator points to the very first entity before we go through it forwards
            layoutEnumerator.reset();
        
            // "Visual order" means when moving through an entity's children that are broken across pages,
            // page layout takes precedence and we avoid elements in other pages and move to others on the same page
            System.out.println("Traversing from first to last, elements between pages separated:");
            traverseLayoutForward(layoutEnumerator, 1);
        
            // Our enumerator is conveniently at the end of the collection for us to go through the collection backwards
            System.out.println("Traversing from last to first, elements between pages separated:");
            traverseLayoutBackward(layoutEnumerator, 1);
        
            // "Logical order" means when moving through an entity's children that are broken across pages,
            // node relationships take precedence
            System.out.println("Traversing from first to last, elements between pages mixed:");
            traverseLayoutForwardLogical(layoutEnumerator, 1);
        
            System.out.println("Traversing from last to first, elements between pages mixed:");
            traverseLayoutBackwardLogical(layoutEnumerator, 1);
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutForward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNext());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order
        /// </summary>
        private void traverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackward(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePrevious());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection front-to-back, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutForwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveFirstChild()) {
                    traverseLayoutForwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.moveNextLogical());
        }
        
        /// <summary>
        /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Logical" order
        /// </summary>
        private void traverseLayoutBackwardLogical(LayoutEnumerator layoutEnumerator, int depth) throws Exception {
            do {
                printCurrentEntity(layoutEnumerator, depth);
        
                if (layoutEnumerator.moveLastChild()) {
                    traverseLayoutBackwardLogical(layoutEnumerator, depth + 1);
                    layoutEnumerator.moveParent();
                }
            } while (layoutEnumerator.movePreviousLogical());
        }
        
        /// <summary>
        /// Print information about layoutEnumerator's current entity to the console, indented by a number of tab characters specified by indent
        /// The rectangle that we process at the end represents the area and location thereof that the element takes up in the document
        /// </summary>
        private void printCurrentEntity(LayoutEnumerator layoutEnumerator, int indent) throws Exception {
            String baseString = "\t";
            String tabs = StringUtils.repeat(baseString, indent);
        
            if (tabs.equals(layoutEnumerator.getKind())) {
                System.out.println(MessageFormat.format("{0}-> Entity type: {1}", tabs, layoutEnumerator.getType()));
            } else {
                System.out.println(MessageFormat.format("{0}-> Entity type & kind: {1}, {2}", tabs, layoutEnumerator.getType(), layoutEnumerator.getKind()));
            }
        
            if (layoutEnumerator.getType() == LayoutEntityType.SPAN) {
                System.out.println(MessageFormat.format("{0}   Span contents: \"{1}\"", tabs, layoutEnumerator.getText()));
            }
        
            Rectangle2D leRect = layoutEnumerator.getRectangle();
            System.out.println(MessageFormat.format("{0}   Rectangle dimensions {1}x{2}, X={3} Y={4}", tabs, leRect.getWidth(), leRect.getHeight(), leRect.getX(), leRect.getY()));
            System.out.println(MessageFormat.format("{0}   Page {1}", tabs, layoutEnumerator.getPageIndex()));
        }