def pprint_page_hierarchy(doc: Doc, iref: complex = None, n: int = 0, level: int = 0, accu: str =''):
    """Pretty print the tree hierarchy of pages."""
    if not iref:
        cat, cat_iref = catalog(doc)
        pages = get_object(doc, cat['/Pages'])
        pcount = get_object(doc, pages['/Count'])
        accu += f"Page count = {pcount}\n"
        iref = cat['/Pages']
        node = pages
    else:
        node = get_object(doc, iref)
    level += 1
    offset = "    " * level
    if node['/Type'] == '/Pages':
        kids = node['/Kids']
        accu += f"{offset} /Pages node at {iref}, kids count = {len(kids)}:\n"
        for kid in kids:
            accu, n = pprint_page_hierarchy(doc, kid, n, level, accu)
    elif node['/Type'] == '/Page':
        accu += f"{offset} /Page [{n}] at {iref} with content(s) at {node.get('/Contents')}\n"
        n += 1
    level -= 1
    if level == 0:
        print(accu)
    return accu, n
Pretty print the tree hierarchy of pages.
pdfsyntax/docstruct.py