def remove_pages(doc: Doc, del_pages) -> Doc:
    """Remove one (an int) or more (a set of int) pages."""
    new_doc = copy_doc(doc, revision='SAME')
    if type(del_pages) != set:
        del_pages = {del_pages}
    pages = flat_page_tree(new_doc)
    del_ref = {pages[p][0] for p in del_pages}
    keep_ref = {p[0] for p in pages} - del_ref
    del_dep = set()
    keep_dep = set()
    for i in del_ref:
        del_dep = del_dep | dependencies(new_doc, i)
    for i in keep_ref:
        keep_dep = keep_dep | dependencies(new_doc, i)
    for ref in del_ref:
        parent = get_object(new_doc, ref)['/Parent']
        new_parent = get_object(new_doc, parent)
        kids = new_parent['/Kids']
        kids.remove(ref)
        new_parent['/Count'] = new_parent['/Count'] - 1
        new_doc = update_object(new_doc, int(parent.imag), new_parent, immut=False)
        while '/Parent' in new_parent:
            p = new_parent['/Parent']
            new_parent = get_object(new_doc, p)
            new_parent['/Count'] = new_parent['/Count'] - 1
            new_doc = update_object(new_doc, int(p.imag), new_parent, immut=False)
    for ref in del_dep - keep_dep:
        new_doc = update_object(new_doc, int(ref.imag), None, immut=False)
    return new_doc
Remove one (an int) or more (a set of int) pages.
pdfsyntax/docstruct.py