'Removes any outline/bookmark entries that are not a part of the
specified page set.'

def _trim_outline(self, pdf, outline, pages):

    new_outline = []
    prev_header_added = True
    for (i, o) in enumerate(outline):
        if isinstance(o, list):
            sub = self._trim_outline(pdf, o, pages)
            if sub:
                if (not prev_header_added):
                    new_outline.append(outline[(i - 1)])
                new_outline.append(sub)
        else:
            prev_header_added = False
            for j in range(*pages):
                if (pdf.getPage(j).getObject() == o['/Page'].getObject()):
                    o[NameObject('/Page')] = o['/Page'].getObject()
                    new_outline.append(o)
                    prev_header_added = True
                    break
    return new_outline
