4

I have folders of images and I am creating a pdf out of them using imagemagick convert tool.

convert Chapter1/*.jpg Chapter2/*.jpg Chapter3/*.jpg book.pdf

I converts creates the pdf fine, however I want to have a table of contents on the left pane, which has links to pages as shown below enter image description here

What tool can I use to create that for a pdf file ? convert does not have ability to achieve that, it only creates a flat pdf.

1 Answer 1

2

What I see in your image are bookmarks, not a table of content. Here is how you can add bookmarks in an existing pdf. I assume your pdf is input.pdf. The info file will be named filename.info, but this name does not matter.

Step 1: Use pdftk to dump the current meta-data

pdftk 'input.pdf' dump_data > 'filename.info'

Step 2: Edit filename.info. For each bookmark, add at the top of the file the following lines:

BookmarkBegin
BookmarkTitle: name
BookmarkLevel: level
BookmarkPageNumber: page number
  • name is the name of the bookmark
  • level starts at 1. Every new level remains the same, increases by 1 or goes back to a previous level in the file.
  • page number is the number of the page you will go to when you click on the bookmark.

The page number is needed, but only used by pdftk to create the link to the page with that number. The page numbers do not have to be in increasing order. For example, even if the index is at the end of the pdf, you can put the corresponding bookmark just after the cover page.

Step 3: Update the meta-data:

pdftk 'input.pdf' update_info 'filename.info' output 'output.pdf'
1
  • This is exactly what I was looking for, thank you. Oct 13, 2023 at 22:17

You must log in to answer this question.

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