Skip to content

Instantly share code, notes, and snippets.

@tuurep
Last active January 30, 2026 20:47
Show Gist options
  • Select an option

  • Save tuurep/e675a44e7979af0d4a05b7fa3b8ce344 to your computer and use it in GitHub Desktop.

Select an option

Save tuurep/e675a44e7979af0d4a05b7fa3b8ce344 to your computer and use it in GitHub Desktop.
Add/fix PDF bookmarks with cpdf

PDF bookmarks with cpdf

https://aur.archlinux.org/packages/cpdf

Adding bookmarks

If the PDF already has bookmarks, but they're bad:

$ cpdf -list-bookmarks foo.pdf > bookmarks.txt

Otherwise, create bookmarks.txt. It has this format:

0 "First Chapter" 4
1 "Subchapter Foo" 6
1 "Subchapter Bar" 8
0 "Second Chapter" 12

i.e. level, title, page

To replace the bookmarks:

$ cpdf -add-bookmarks bookmarks.txt foo.pdf -o out.pdf

Check that the index is as you want in out.pdf. In the end:

$ mv out.pdf foo.pdf

Scrolling down a page

Full reference: https://www.coherentpdf.com/cpdfmanual/cpdfmanualch6.html

See "6.1.1 Destinations".

Typically, scrolling down a page would look something like this:

0 "Foo" 25 "[25/XYZ 0 60 null]"

Takes trial and error to get that Y value where you want it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment