def getToC(doc, simple = True):
def recurse(olItem, liste, lvl):<EOL><INDENT>'''<STR_LIT>'''<EOL>while olItem:<EOL><INDENT>if olItem.title:<EOL><INDENT>title = olItem.title<EOL><DEDENT>else:<EOL><INDENT>title = "<STR_LIT:U+0020>"<EOL><DEDENT>if not olItem.isExternal:<EOL><INDENT>if olItem.uri:<EOL><INDENT>page = olItem.page + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>page = -<NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>page = -<NUM_LIT:1><EOL><DEDENT>if not simple:<EOL><INDENT>link = getLinkDict(olItem)<EOL>liste.append([lvl, title, page, link])<EOL><DEDENT>else:<EOL><INDENT>liste.append([lvl, title, page])<EOL><DEDENT>if olItem.down:<EOL><INDENT>liste = recurse(olItem.down, liste, lvl+<NUM_LIT:1>)<EOL><DEDENT>olItem = olItem.next<EOL><DEDENT>return liste<EOL><DEDENT>if doc.isClosed:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>olItem = doc.outline<EOL>if not olItem: return []<EOL>lvl = <NUM_LIT:1><EOL>liste = []<EOL>return recurse(olItem, liste, lvl)<EOL>
Create a table of contents.

    Args:
        simple: a bool to control output. Returns a list, where each entry consists of outline level, title, page number and link destination (if simple = False). For details see PyMuPDF's documentation.