Skip to content

Instantly share code, notes, and snippets.

@kwsp
Last active November 6, 2021 04:38
Show Gist options
  • Save kwsp/c43de80ac9e5114cd9c17c82c50fe6cf to your computer and use it in GitHub Desktop.
Save kwsp/c43de80ac9e5114cd9c17c82c50fe6cf to your computer and use it in GitHub Desktop.
Add outline/bookmark to a PDF file for easy navigation.

Add "outline" to a PDF file

Install pdftk

Dump the metadata of the pdf file:

pdftk [pdf_to_update] dump_data_utf8 > meta.txt

If the book already contains some bookmarks, it will look something like

...
BookmarkBegin
BookmarkTitle: 11. Diffuse Optical Tomography
BookmarkLevel: 1
BookmarkPageNumber: 262
BookmarkBegin
BookmarkTitle: 11.1. Introduction
BookmarkLevel: 2
BookmarkPageNumber: 262
BookmarkBegin
BookmarkTitle: 11.2. Modes of Diffuse Optical Tomography
BookmarkLevel: 2
BookmarkPageNumber: 262
...

Scrape the TOC for the file from some official source and convert into the format above with a custom script. Add this back into the meta.txt file.

Finally, dump the metadata back into the PDF.

pdftk [pdf_to_update] update_info_utf8 meta.txt output [updated_pdf]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment