public class LayoutCollector
extends java.lang.Object
This class allows to compute page numbers of document nodes.
To learn more, visit the Converting to Fixed-page Format documentation article.
When you create a LayoutCollector and specify a Document document object to attach to, the collector will record mapping of document nodes to layout objects when the document is formatted into pages.
You will be able to find out on which page a particular document node (e.g. run, paragraph or table cell) is located by using the getStartPageIndex(com.aspose.words.Node), getEndPageIndex(com.aspose.words.Node) and getNumPagesSpanned(com.aspose.words.Node) methods. These methods automatically build page layout model of the document and update fields if required.
When you no longer need to collect layout information, it is best to set the getDocument() / setDocument(com.aspose.words.Document) property to null to avoid unnecessary collection of more layout mappings.
| Constructor and Description |
|---|
LayoutCollector(Document doc)
Initializes an instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears all collected layout data.
|
Document |
getDocument()
Gets the document this collector instance is attached to.
|
int |
getEndPageIndex(Node node)
Gets 1-based index of the page where node ends.
|
java.lang.Object |
getEntity(Node node)
Returns an opaque position of the
LayoutEnumerator which corresponds to the specified node. |
int |
getNumPagesSpanned(Node node)
Gets number of pages the specified node spans.
|
int |
getStartPageIndex(Node node)
Gets 1-based index of the page where node begins.
|
void |
setDocument(Document value)
Sets the document this collector instance is attached to.
|
public LayoutCollector(Document doc)
doc - The document to which this collector instance will be attached to.public int getStartPageIndex(Node node) throws java.lang.Exception
java.lang.Exceptionpublic int getEndPageIndex(Node node) throws java.lang.Exception
java.lang.Exceptionpublic int getNumPagesSpanned(Node node) throws java.lang.Exception
getEndPageIndex(com.aspose.words.Node) - getStartPageIndex(com.aspose.words.Node).java.lang.Exceptionpublic void clear()
public Document getDocument()
null afterwards, otherwise the collector continues to accumulate information from subsequent rebuilds of the document's page layout.public void setDocument(Document value)
null afterwards, otherwise the collector continues to accumulate information from subsequent rebuilds of the document's page layout.value - The document this collector instance is attached to.public java.lang.Object getEntity(Node node) throws java.lang.Exception
LayoutEnumerator which corresponds to the specified node. You can use returned value as an argument to LayoutEnumerator.getCurrent() / LayoutEnumerator.setCurrent(java.lang.Object) given the document being enumerated and the document of the node are the same.
This method works for only Paragraph nodes, as well as indivisible inline nodes, e.g. BookmarkStart or Shape. It doesn't work for Run, Cell Row or Table nodes, and nodes within header/footer.
Note that the entity returned for a Paragraph node is a paragraph break span. Use the appropriate method to ascend to the parent line
If you need to navigate to a Run of text then you can insert bookmark right before it and then navigate to the bookmark instead.
If you need to navigate to a Cell node then you can move to a Paragraph node in this cell and then ascend to a parent entity. The same approach can be used for Row and Table nodes.
java.lang.Exception