There is already an application that does this,
pdftk (see also How to preserve bookmarks when rearranging pages of a PDF file with tools like pdftk? - Unix & Linux Stack Exchange):
pdftk in.pdf dump_data output in.info verbose # dump all metadata to file in.info pdftk in2.pdf update_info in.info output out.pdf # write all metadata from file in.info into in2.pdf, generating out.pdf
However, I just got into a situation where
pdftk cannot open my 40+ MB PDF file (which can be opened by
acroread or other tools), and so I'd like to ask here for alternatives: are there any other command line tools that work in Linux that can do the same as above?
exiftool might, but its help is too hard for me to read; and I can see it can read/write individual tags - but not how to dump and update all defined metadata tags at once, like the above
pdftk example does).