Created
March 13, 2019 11:57
-
-
Save amitness/32ee028889cde8fba2e34615b2f9eee2 to your computer and use it in GitHub Desktop.
Read the TOC of a PDF using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pdfminer.pdfparser import PDFParser | |
from pdfminer.pdfdocument import PDFDocument | |
import sys | |
# python tldr.py filename.pdf | |
fp = open(sys.argv[1], 'rb') | |
parser = PDFParser(fp) | |
doc = PDFDocument(parser) | |
outlines = doc.get_outlines() | |
for (level, title, dest, a, se) in outlines: | |
print ' ' * (level - 1) + title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment