Even though they're both java based, I was thinking about the possibility of instead using sejda (command line version of pdfsam) or pdftk, to create the pdf with bookmarks.I'm using pdfunite from poppler
I found that there is now a very similar project which already creates the pdf with bookmarks. It is using gs, so it will have the performance problems I was complaining about, whereas sejda or pdfsam wouldn't.
https://github.com/bronson/pdfdir