Change the Bookmark Numbering on a PDF Document

You have a PDF file and the bookmarks don't match the actual page numbers of the book. Here is an illustration of our PDF problem.

PDF file with pages that mismatch bookmarks.

My search for answer went something like this...

This page will explain how to change the bookmark numbering on a pdf document using only open-source and GPL licensed software.

To begin, you first export the metadata from your pdf document using BeCyPDFMetaEdit.exe (mirror download). Here is an excerpt from BeCyPDFMetaData.exe documentation.

This example exports the metadata and bookmarks from the document Test.pdf into the template file ai.pdf.ini. The PDF document itself is not altered. The parameter -M auto enforces the export of the special value Auto instead of the actual modification date:

BeCyPDFMetaEdit "d:\pdf\ai.pdf" -tf ">" -tm "io" -M auto

So we now have ai.pdf.ini and ai.pdf in our d:\pdf directory.

Next, we need to delete the first pages of the book. Page 1 of the real book starts on page 21 of the PDF. So we want to remove the first 21 pages of the pdf, and export everything else into a new PDF file. To do this we will use pdftk (mirror download)

pdftk A=ai.pdf cat A21-1152 output ai-short.pdf

We now have ai.pdf, ai.pdf.ini, and ai-short.pdf in our d:\pdf directory. Now we edit the ai.pdf.ini file with a text editor, removing the last 21 bookmarks from the metadata.

Delete the extra lines from your pdf metadata file.

Now we need to apply our edited metadata file to our new pdf file.

BeCyPDFMetaEdit "d:\pdf\ai-short.pdf" -tf "d:\pdf\ai.pdf.ini" -tm "o" "Demonstration"

ai-short.pdf now has matching bookmarks and pages. Using python or a bash script, you could automate this entire process into a simple GUI program... which I may do someday. You could also try and change the page numbering without destroying the beginning of the pdf document.

PDF Modification Resources

How to Install BeCyPDFMetaEdit and pdftk

Read the installation instructions, but basically, you put the executables into your /windows/System32 folder. Once you've done that, you can run the files from the command prompt.