You can use pdftk
for this. More info: How to Export and Import PDF Bookmarks.
Export PDF bookmarks on the command-line like this:
pdftk C:\Users\Sid\Desktop\doc.pdf dump_data output C:\Users\Sid\Desktop\doc_data.txt
Import PDF bookmarks from a data file like this:
pdftk C:\Users\Sid\Desktop\doc.pdf update_info C:\Users\Sid\Desktop\doc_data.txt output C:\Users\Sid\Desktop\updated.pdf
pdftk
bookmark format is a little bit tedious to write. Instead I created my own script using bash
, sed
, pdftk
and python3
. Check it out at this repo: https://github.com/SiddharthPant/booky
So now I can create a text file(bkmrks.txt
) like this which takes just 5 minutes to write even for a 1000 page pdf.
{
Title1, 1
Title2, 2
{
Subtitle1, 3
Subtitle2, 4
{
SubSubtitle1, 5
...
}
}
}
and then use my script
./booky.sh pdf_file.pdf bkmrks.txt
this automatically creates a pdf(pdf_file_new.pdf
) that has my bookmarks in it.
This is going to work in *nix systems if instead you are on a Windows machine. Then first install python3
and pdftk
just use the booky.py
file in the repo to convert bkmrks.txt
to pdftk
compatible format
python3 booky.py < bkmrks.txt > output.txt
and then use the export command to generate a dumped data file. Remove the previous bookmarks from that file and insert content of output.txt
instead using a simple copy paste. And then import that data back.