Modifying bookmark opening levels of PDF documents using Coherent PDF Command Line Tools (cpdf)

Sometimes large books or theses may contain many chapters, section and subsections. Reading such PDF documents with the whole table of contents hierarchy shown in the bookmarks panel may be difficult. There is a way to tell PDF viewers to show only a specific level of bookmarks and hide its children. This is done by providing a information about "open"/"closed" status of a bookmark. LaTeX package hyperref  supports that with an option "bookmarksopenlevel". Here is an example LaTeX file to produce PDF documents with different bookmark opening levels:

In order to compile it, we need a Makefile with bookmark opening levels passed as arguments to pdflatex:

Also we need to install Coherent PDF Command Line Tools to analyze and modify bookmarks in a PDF document:

Other tools such as pdftk do not support bookmark opening levels.

Let's compile all three versions:

Generated PDF documents test_lvl0.pdf, test_lvl1.pdf and test_lvl2.pdf, when opened with PDF viewers (okular, evince etc.) will have different initial views:

and the PDF documents will have different "open"/"closed" status in the bookmark information:

Also cpdf allows to add custom bookmarks with specifying bookmark opening levels:

When test_mod.pdf file is opened in a PDF viewer, the initial look is like in the figure:

As expected, bookmarks at pages 2 and 4 are collapsed. This provides flexibility in choosing custom opening levels for chosen bookmarks.

In conclusion, cpdf is a useful tool which can be used to modify table of contents bookmarks of large books. An example use is described here.

Leave a Reply

Your email address will not be published. Required fields are marked *