I use https://github.com/Krasjet/pdf.tocgen.

It's not quite fully automatic, but it certainly saves a lot of time over doing it completely by hand.

Very nice! I’ll check it out.