Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am using pdftk to rearrange pages of a pdf file with bookmarks/outlines, but after that, the output file lost the bookmarks of the original.

My command is pdftk in.pdf cat 1-22 43 23-42 44-end output out.pdf.

I was wondering how I could keep the bookmarks while rearranging pages?

share|improve this question
add comment

3 Answers

You need to do pdftk in.pdf dump_data > in.info, then add the update_info parameter when generating the out.pdf. Quoting from man pdftk:

update_info <info data filename | - | PROMPT>

Changes the metadata stored in a single PDF's Info dictionary to match the input data file. The input data file uses the same syntax as the out‐ put from dump_data. Non-ASCII characters should be encoded as XML numerical entities. This does not change the metadata stored in the PDF's XMP stream, if it has one. For example:

             pdftk in.pdf update_info in.info output out.pdf

  update_info_utf8 <info data filename | - | PROMPT>

Same as update_info except that the input is encoded as UTF-8.

share|improve this answer
    
Thanks! How shall I get this file "in.info"? –  Tim Jul 20 '11 at 15:22
    
@Tim: edited. I hope it's clear now. You need to use dump_data_utf8 for update_info_utf8 to work, of course. –  Philomath Jul 20 '11 at 15:28
2  
Thanks! It still doesn't work. My commands are in three steps: pdftk in.pdf dump_data > in.info, pdftk in.pdf cat 1-22 43 23-42 44-end output out.pdf and pdftk out.pdf update_info in.info output out1.pdf There are still no bookmarks in out1.pdf. ` –  Tim Jul 20 '11 at 17:10
    
@Tim I can confirm that this does indeed not work. Have you found any solution to this by any chance? –  Glutanimate Feb 15 '13 at 1:47
1  
My cursory Google trawling suggests that bookmarks aren't handled at all. –  vonbrand Feb 16 '13 at 5:03
show 2 more comments

Reading the man page with care, it says that update_info takes data in whatever format dump_data generates. That presumably would have to be adjusted according to the page shuffling. Doesn't sound impossible, but automatic it isn't.

The PDFtk site only gives the above hit and creating/editing bookmarks as results. All Google knows about the matter of bookmarks in PDF and reorganizing, is hits on the above operations and lyrical expositions on the marvels they offer, and this thread ;-).

So it seems it can't be done. The comments suggest some possibilities, which didn't work when tried.

share|improve this answer
add comment

Here is a working solution. However you will need to adjust it to fit your needs.

In my example i removed the first page of a PDF, and then i needed to update the bookmarks to point to the correct locations.

  1. remove page 1 from in.pdf:

    pdftk A=in.pdf cat A2-end output temp.pdf
    
  2. create a in.info file from in.pdf:

    pdftk in.pdf dump_data > in.info
    
  3. in.info needs to be corrected in my case, since i will remove a page.

    Thus, i need to decrease BookmarkPageNumber by one for the bookmarks to lead to the correct pages.

    php code:

    $file = "in.info";
    $data = file_get_contents($file);
    
    foreach (explode("\n", $data) as $row) {
        $tmp = explode(": ", $row);
    
        if ($tmp[0] == "BookmarkPageNumber") {
            if ($tmp[1] != "1") $tmp[1]--;
            echo $tmp[0].": ".$tmp[1]."\n";
        } else {
            echo $row."\n";
        }
    }
    
  4. create final out.pdf:

    pdftk temp.pdf update_info in2.info output out.pdf
    

tested working on debian using pdftk 2.01

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.