user3084455
user3084455

Reputation: 926

How can I read the bookmarks from a pdf in python?

I have been searching high and low, pyPdf, pyPdf2, pdfminer and the like, all I want is to read the bookmarks of a pdf, and their correlating pages, so that if the bookmark "chapter 1" is on page 5, and I write print(bookmarks) it will print "chapter 1, 5" or in that direction, any ideas? thanks!

Upvotes: 2

Views: 2464

Answers (1)

johnwhitington
johnwhitington

Reputation: 2763

You could use the cpdf command line tool, and then parse the results:

cpdf -list-bookmarks file.pdf

will produce something like

0 "Purpose" 1 
0 "To help students visually organize similarities and differences between three ideas, objects, or sets." 1 
0 "To increase awareness of relationships between ideas, objects, or sets" 2 open
1 "Teacher Instructions" 3

where the columns are level in tree, text of bookmark, page number it points to.

Upvotes: 2

Related Questions