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?

5 Answers 5


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

  • 4
    Worked for me too. Maybe you could add a hint on how to execute your script (no idea how...) or add a python script: #!/usr/bin/python output = open('res.info','w') with open('temp.info','r') as f: for line in f: if line.startswith("BookmarkPageNumber"): output.write( "BookmarkPageNumber: "+ str(int(line.split()[1])+1)+"\n") else: output.write(line)
    – Vser
    Commented Jun 3, 2015 at 14:23
  • I use dump_data_utf8 and update_info_utf8 because bookmarks might contain special characters.
    – myrdd
    Commented Jul 22, 2020 at 21:34
  • The data dump in.info also contains NumberOfPages: X that may need updating, depending on each case
    – pdpino
    Commented Mar 18, 2022 at 0:17

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.


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.

  • Thanks! How shall I get this file "in.info"?
    – Tim
    Commented Jul 20, 2011 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
    Commented Jul 20, 2011 at 15:28
  • 3
    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
    Commented Jul 20, 2011 at 17:10
  • @Tim I can confirm that this does indeed not work. Have you found any solution to this by any chance? Commented Feb 15, 2013 at 1:47
  • 1
    My cursory Google trawling suggests that bookmarks aren't handled at all.
    – vonbrand
    Commented Feb 16, 2013 at 5:03

"pdfmod" is a simple graphical tool which allows to remove one or mode pages from an existing PDF. It is just matter of a few clicks. It also preserves the content information and cross-linking in the pdf.

"pdftk" works good and I was using it for a long time but I used to lose content after removing one or two pages from the pdf. Those pdf files which are tested in "pdftk" and "pdfmod" are created from openoffice.


  • pdfmod seems better than pdftk when it comes to preserving metadata. A diff of exiftool output shows that pdfmod preserves the metadata, but pdftk does not preserve everything, even if you use dump_data_utf8 & update_info_utf8. Commented Nov 29, 2018 at 7:43

qpdf works like a charm at least under cygwin. it preserves the links as long as you do not use the --empty option :

qpdf input.pdf --pages input.pdf 1,4,5,7-r8,2,3,r7-z -- output.qpdf.pdf

(rN is to select a page indexed from end, z the last page)

  • Works for me as well under Arch Linux with qpdf Version 11.5.0. However, while this will update the page number of the bookmarks, it will not reorder the bookmarks, which may be annoying if you e.g. move a chapter to the end of book. So I still had to edit the bookmarks with pdftk (but this is still easier than changing every page number).
    – jkd
    Commented Aug 23, 2023 at 16:06

You must log in to answer this question.

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