def get_toc(path): infile = open(path, 'rb') parser = PDFParser(infile) doc = PDFDocument(parser) toc = list() for (level, title, dest, a, structelem) in doc.get_outline(): toc.append((level, title)) return toc