public class TocItem extends Object
An instance of TocItem
class is used as return value of Parser.getToc()
method. See the usage examples there.
Constructor and Description |
---|
TocItem(int depth,
String text,
Integer pageIndex)
Initializes a new instance of the TocItem class.
|
Modifier and Type | Method and Description |
---|---|
TextReader |
extractText()
Extracts a text from the document to which TocItem object refers.
|
int |
getDepth()
Gets the depth level.
|
Integer |
getPageIndex()
Gets the page index.
|
String |
getText()
Gets the text.
|
public int getDepth()
public String getText()
public Integer getPageIndex()
null
if it isn't set.public TextReader extractText()
The following example how to extract a text by the an item of table of contents:
// Create an instance of Parser class
try (Parser parser = new Parser(Constants.SampleDocxWithToc)) {
// Get table of contents
Iterable<TocItem> tocItems = parser.getToc();
// Check if toc extraction is supported
if (tocItems == null) {
System.out.println("Table of contents extraction isn't supported");
}
// Iterate over items
for (TocItem tocItem : tocItems) {
// Print the text of the chapter
try (TextReader reader = tocItem.extractText()) {
System.out.println("----");
System.out.println(reader.readToEnd());
}
}
}
TextReader
class with the extracted text.