I want to transfer bookmarks from a series of uncompressed pdf files to their compressed copies (these copies do not have the original bookmarks).

I know how to do this one by one using pdftk. First I have to extract the bookmarks:

pdftk file.pdf dump_data output file.txt

and then I have to transfer them to the compressed copy:

pdftk file_mrc.pdf update_info file.txt output file_mrc_updated.pdf

(my compressed pdf files have that mrc suffix).

I have hundreds of pdf files in this situation, with the correspondent compressed pdf copy, so I want to automatize the procedure.

I found a way to extract the bookmarks from all the files with find, but I don't know how to use this command for dumping the bookmarks on the copies:

find . -type f ! -name "*mrc*" -exec pdftk '{}' dump_data output {}.txt ';'

1 Answer 1


Assuming your filenames don't have weird things like linebreaks in them, something like this might work:

find -type f ! -name "*mrc*" | while read file ; do pdftk "$file" dump_data output "${file%.pdf}.txt" && pdftk "${file%.pdf}_mrc.pdf" update_info "${file%.pdf}.txt" output "${file%.pdf}_mrc_updated.pdf" ; done

There are more readable ways of doing it with a traditional script however, if you'd prefer.

for file in *.pdf ; do
    if [[ "$file" =~ "mrc" ]] ; then
    pdftk "$file" dump_data output "${commonname}.txt"
    pdftk "${commonname}_mrc.pdf" update_info "${commonname}.txt" output "${commonname}_mrc_updated.pdf" 

(That assumes they're all in the same folder.)

P.S. This question is really more about scripting than it is about copying bookmarks; you've got that part figured out. Maybe change the title?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .