Add bookmarks into PDF using PyPDF2
To use the scripts here, you must install or download PyPDF2 first.
-
Make
add_bookmarks.pyexecutable:$ chmod +x add_bookmarks.py
-
Turn to your target PDF (e.g.
MyBook.pdf), record bookmark titles and page numbers of the PDF into a TEXT file (e.g.my_bookmarks.txt) by hand with the following format:""|
For samples, see sample_bookmarks.txt.
-
Generate a copy of
MyBook.pdfwith additional bookmarks specified bymy_bookmarks.txt:./add_bookmarks.py MyBook.pdf my_bookmarks.txt
The default filename of the output PDF is MyBook(new).pdf. Of course you can specify the filename explicitly:
./add_bookmarks.py MyBook.pdf my_bookmarks.txt MyBook_with_bookmarks.pdf