PDF Bookmarks – How to Add and Edit Bookmarks in a PDF File

pdfpdftk

By getting metadata from some pdf files with bookmarks by pdftk, I observe the format of bookmarks in pdf metadata. So I am guessing that with pdftk, it is possible to add and edit bookmarks of a pdf file.

Here are three steps that I follow:

  1. I firstly get the metadata (including bookmarks if any) from a pdf
    file into a text file by pdftk in.pdf dump_data > in.info.
  2. Next I add some bookmarks into the metadata text file in.info, changing it
    from

    InfoKey: Creator
    InfoValue: PScript5.dll Version 5.2
    InfoKey: Title
    InfoValue: SSReader Print.
    InfoKey: Producer
    InfoValue: Acrobat Distiller 7.0 (Windows)
    InfoKey: Author
    InfoValue: Administrator
    InfoKey: ModDate
    InfoValue: D:20050605073244+08'00'
    InfoKey: CreationDate
    InfoValue: D:20050605073244+08'00'
    PdfID0: 591a87c91dc76881fdf2ccf3811e72a5
    PdfID1: 6b6ab11de8824e438e4f5eb1d85ec72
    NumberOfPages: 400
    PageLabelNewIndex: 1
    PageLabelStart: 1
    PageLabelNumStyle: DecimalArabicNumerals
    

    to

    InfoKey: Creator
    InfoValue: PScript5.dll Version 5.2
    InfoKey: Title
    InfoValue: SSReader Print.
    InfoKey: Producer
    InfoValue: Acrobat Distiller 7.0 (Windows)
    InfoKey: Author
    InfoValue: Administrator
    InfoKey: ModDate
    InfoValue: D:20050605073244+08'00'
    InfoKey: CreationDate
    InfoValue: D:20050605073244+08'00'
    PdfID0: 591a87c91dc76881fdf2ccf3811e72a5
    PdfID1: 6b6ab11de8824e438e4f5eb1d85ec72
    NumberOfPages: 400
    BookmarkBegin
    BookmarkTitle: Front cover
    BookmarkLevel: 1
    BookmarkPageNumber: 1
    BookmarkBegin
    BookmarkTitle: About the Author
    BookmarkLevel: 1
    BookmarkPageNumber: 5
    BookmarkBegin
    BookmarkTitle: Title page
    BookmarkLevel: 1
    BookmarkPageNumber: 6
    BookmarkBegin
    BookmarkTitle: Copyright page
    BookmarkLevel: 1
    BookmarkPageNumber: 7
    BookmarkBegin
    BookmarkTitle: Foreword
    BookmarkLevel: 1
    PageLabelNewIndex: 1
    PageLabelStart: 1
    PageLabelNumStyle: DecimalArabicNumerals
    
  3. Then I try to put the edited metadata back to the pdf file by pdftk
    in.pdf update_info in.info output out.pdf
    .

But when I open the new pdf file out.pdf in evince or adobe reader, there is no bookmark in the new pdf file.

If I get the metadata from the new pdf file out.pdf by pdftk out.pdf dump_data > out.info, there will be no bookmarks in out.info. It looks like the bookmarks were not added successfully.

I was wondering if there are some mistakes? How shall I add and edit bookmarks of a pdf file, not necessarily by pdftk?

Best Answer

It looks to me like from version 1.45 (2012-12-06), pdftk does allow modification of bookmarks via the update_info command:

You can now add or change a PDF’s bookmarks using update_info.

via: http://www.pdflabs.com/docs/pdftk-version-history/

Related Question