1

Many PDF documents contain a hierarchical table of contents. I am not referring to the ToC visible on a page-- what I mean is the metadata that is used to generate the sidebar links when viewing a PDF with an app like Preview. How can I extract it? I am not looking for a GUI app, as I am going to be extracting this information from many documents with a script.

  • Can you ask this in a way which doesn't sound like you are asking for a software recommendation? superuser.com/help/on-topic – krowe Mar 10 '15 at 0:00
  • @krowe Hmm well I think the best I can do is remove "with a command line tool or something similar". I will be happy with a software recommendation, but I am also open to a more general description of how to access this metadata. I feel that this is a concrete, well-scoped question that meets the posting criteria. It just happens that the answer may involve a software recommendation. – Sean Mackesey Mar 10 '15 at 0:06
0

The python package pdfminer is able to extract this information. Use the dumppdf.py script that comes with the package.

dumppdf.py -T /path/to/my/PDF

Produces XML of the table of contents.

NOTE: Credit @krowe for linking the source of this answer in the comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.