0

I just want to access table of content/Catalogue/Index Page from the pdf file using android pdfviewer by using barteksc. When I successfully load the pdf file from assets, its shows table of content of the file in debugger mode at console. I was trying to write it manually in my project but I shocked to see it already in my console showing all table of content in text form with title of each page and page number. Here I am attaching the screenshot of console where pdf file table of content showing but unable to access them enter image description here

I have gone through its meta data but did not find any content. Please help me to find and access this table of content which is showing in the picture of console. thanks for your response

Shani74
  • 43
  • 8

1 Answers1

0

Finally, afer many days of searching I got solution myself and I think it sould not be take time because solution was right in the code but I was unable to find. Anyhow I want to share solution with community.

We can access table of content from pdf file which has built in table of content while designing by using this code.

 printBookmarksTree(pdfView.getTableOfContents(), "-");

call above line in loadComplete method of barteksc pdfviewer. and then printBookmarksTree sould iterate the items and populate items in your declared list. Look like below.

public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
    for (PdfDocument.Bookmark b : tree) {

        BookListViewItems e = new BookListViewItems(b.getTitle(), b.getPageIdx() + "");
        bookSafhatListView.add(e);
        if (b.hasChildren()) {
            printBookmarksTree(b.getChildren(), sep + "-");
        }
    }
}

by the above code, table of content of pdf file will be in bookSafhatListView. Now you can utilize this list according to your needs.

Shani74
  • 43
  • 8