Here are the steps to extract table of contents from the document:
Instantiate the Parser object for the initial document;
Call the getToc() method and obtain the collection of TocItem objects;
Check if collection isn’t null (table of contents extraction is supported for the document);
Iterate through the collection and get the page index to extract a page text from the document.
The following example shows how to extract table of contents from an EPUB file:
constgroupdocs=require('@groupdocs/groupdocs.parser');// Create an instance of Parser class
constparser=newgroupdocs.Parser('sample.epub');try{if(!parser.getFeatures().isText()){// Check if text extraction is supported
console.log("Text extraction isn't supported.");}elseif(!parser.getFeatures().isToc()){// Check if toc extraction is supported
console.log("Toc extraction isn't supported.");}else{// Get table of contents
consttoc=parser.getToc();// Iterate over items
constit=toc.iterator();while(it.hasNext()){constitem=it.next();// Print the Toc text
console.log(item.getText());// Check if page index has a value
constpageIndex=item.getPageIndex();if(pageIndex===null){continue;}// Extract a page text
constreader=parser.getText(pageIndex);try{console.log(reader.readToEnd());}finally{reader.close();}}}}finally{parser.close();}process.exit(0);
More resources
Advanced usage topics
To learn more about document data extraction features and get familiar how to extract text, images, forms and more, please refer to the advanced usage section.
Free online document parser App
Along with the full-featured library we provide simple, but powerful free Apps.
You are welcome to extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Parser App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.