def pprint_index(doc: Doc, compact: bool = False):
    """Pretty print index as tabular data."""
    if compact:
        W_NUM = 7
    else:
        W_NUM = 17
    nb_obj = len(doc.index[-1])
    ver = len(doc.index)
    matrix = [[None] * nb_obj for x in range(ver)]
    maxs = [1] * ver
    for i in range(nb_obj):
        line = f"{i:<{W_NUM}}"
        o_gen, o_ver, doc_ver = "", "", ""
        abs_pos, env_num, o_pos = "", "", ""
        for j in range(ver):
            if i > len(doc.index[j]) - 1:
                matrix[j][i] = '-'
                continue
            cell = 'idem'
            x = doc.index[j][i]
            if x:
                if type(x) == list:
                    x = x[0]
                o_gen_new = x.get('o_gen', '')
                o_ver_new = x.get('o_ver', '')
                doc_ver_new = x.get('doc_ver', '')
                abs_pos_new = x.get('abs_pos', '-')
                env_num_new = x.get('env_num', '')
                o_pos_new = x.get('o_pos', '')
                deleted = x.get('DELETED')
                if deleted:
                    cell = "Deleted "
                elif o_gen_new != o_gen or o_ver_new != o_ver or doc_ver_new != doc_ver:
                    o_gen, o_ver, doc_ver = o_gen_new, o_ver_new, doc_ver_new
                    cell = f"{o_gen}/{o_ver}/{doc_ver}"
                if abs_pos_new != abs_pos:
                    abs_pos = abs_pos_new
                    cell += f" {abs_pos}"
                if env_num_new != env_num or o_pos_new != o_pos:
                    env_num, o_pos = env_num_new, o_pos_new
                    cell += f" {env_num}"
            matrix[j][i] = cell
            if len(cell) > maxs[j]:
                maxs[j] = len(cell)
    for i in range(1, nb_obj):
        line = f"{i:<{W_NUM}}"
        for j in range(ver):
            line += f"| {matrix[j][i]:{maxs[j]}} "
        print(line)
    print('')
    i = 0
    line = f"{'0 (trailer)':<{W_NUM}}"
    if compact:
        line += '\n' + ' ' * W_NUM
    for j in range(ver):
        line += f"| {matrix[j][i]:{maxs[j]}} "
    print(line)
    for k in 'abs_pos startxref_pos xref_table_pos xref_stream_pos xref_stream_num'.split():
        line = f"{k:<{W_NUM}}"
        if compact:
            line += '\n' + ' ' * W_NUM
        for j in range(ver):
            if type(doc.index[j][0]) == list:
                val = 'multiple'
            else:
                val = doc.index[j][0].get(k, '-')
            val = f"{val} "
            line += f"| {val:{maxs[j]}} "
        print(line)
    return
Pretty print index as tabular data.
pdfsyntax/docstruct.py