Skip to content

Is there a way to get the document's ToC or Outline? #456

Answered by jsvine
inf3rnus asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Aaron, and thanks for the thoughtful question. In pdfplumber, you still get (undocumented*) access to the pdfminer.PDFDocument object, via .doc. For instance:

import pdfplumber
with pdfplumber.open("path/to/my.pdf") as pdf:
    print(list(pdf.doc.get_outlines()))

Does that work for you?

If some of the return values are <PDFObjRef:___> objects, you can resolve those via pdfplumber.utils.resolve(...) / pdfplumber.utils.resolve_all(...).

* I think it probably is worth adding more explicit documentation about this.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@inf3rnus
Comment options

Answer selected by jsvine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants