Copy Table of Contents from one PDF to another
The XMP metadata and TOC/bookmarks are 2 different things. While the TOC in a PDF file can be read using the CGPDF* functions, it cannot be duplicated in another PDF file because the CGPDF* API does not let you create PDF objects and insert them in a PDF file.
I recently did a lot of merging pdf's together and also populating form data. I would check out PDF Toolkit as it really helped me out. You can execute it from within your code.