PDF Table of Contents

Overview

Not all PDF documents will have a Table of Contents, to check to see if the current document instance contains a Table of Contents an application developer should call the isTOCEnabled method once the document has fully loaded.

val hasTOC:Boolean = documentView.isTOCEnabled

if (hasTOC) {
    // enable UI (e.g. button/gesture) responsible for invoking TOC display
}

In order to show the pre-built Table of Contents UI an application developer simply needs to call the tableOfContents method as follows:

documentView.tableOfContents()

Note

Table of Contents is also known as “Bookmarks” or “Outline”.

Enumerating a Table of Contents

To get information about the table of contents the following API should be used to enumerate the listing:

documentView?.let { dv ->
    // get the TOC entries
    val entries = ArrayList<TocData>()

    dv.enumeratePdfToc(object : DocumentView.EnumeratePdfTocListener {
        override fun nextTocEntry(handle: Int, parentHandle: Int, page: Int,
                                  label: String, url: String, x: Float, y: Float) {
            val entry: TocData = TocData(handle, parentHandle, page, label, url, x, y)
            entries.add(entry)
        }
        override fun done() {

        }
    })
}

private class TocData constructor(var handle: Int,
                                  var parentHandle: Int,
                                  var page: Int,
                                  var label: String,
                                  var url: String,
                                  var x: Float,
                                  var y: Float) {
    var level:Int = 0
    var tabIndent:String = ""
}

This software is provided AS-IS with no warranty, either express or implied. This software is distributed under license and may not be copied, modified or distributed except as expressly authorized under the terms of that license. Refer to licensing information at artifex.com or contact Artifex Software Inc., 39 Mesa Street, Suite 108A, San Francisco CA 94129, United States for further information.

Discord logo