This is a tool by huuhoa for exporting OneNote documents to PDF (with a table of contents) by script.
It was hosted on CodePlex, but CodePlex is transitioning to a read-only archive. I use this tool regularly and find it to be very useful, so I migrated the files over here.
I've included the source, the executable and the docs.
Although written for OneNote 2007, I am currently using it with OneNote 365 ProPlus Version 1711 and finding it to work without fault.
This is open source, under the Microsoft Public License.