Export (part of) a database as a PDF with TOC


I use Devonthink as my repository for notes on various topics. I would like to be able to export all of them as one PDF file, while recreating the structure of the folders/files in the database as the TOC in the PDF. This way I could review them using my e-Ink reader. Ideally the script would convert to PDF all types of documents that can be displayed by DT.

I know that some parts of this script have already been implemented (here and here), but the ability to convert multiple file formats, merge them in one single PDF and add a TOC would be a great feature.