https://aur.archlinux.org/packages/cpdf
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
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.