26 August 2014

Periodically, there is a need to remove all bookmarks from a PDF. Sometimes the bookmarks become unwieldy. Sometimes planned document mergers render the bookmarks superfluous. Other times, you just don't want them. Regardless of the motivation, pdftk seems like an appropriate tool for quick adjustments of this sort. Unfortunately, as its features have evolved, this is a use case of apparently secondary concern.

The Goal

Remove all bookmarks from a PDF via the command-line using PDFtk.

Failed Solutions Seen Elsewhere

There are two solutions that do not work with pdftk 2.02, although they may have worked for some older version.

data_dump/update_info

First, the bookmarks appear in the data_dump and can beĀ updated via update_info. The update_info documentation confirms that it "changes the bookmarks...," but it does not make any reference to removing all bookmarks. If the info file that you apply to the PDF contains zero bookmarks, then pdftk ignores the bookmarks entirely and leaves them intact. Thus, this method can be used to update bookmarks or to remove most bookmarks, but it cannot be used to remove ALL bookmarks.

cat

Second, there are assertions that simply using a trivial case of the concatenation command will strip out the bookmarks. For example:

pdftk example.pdf cat output nobookmarks.pdf

However, the version history indicates that bookmarks are preserved when merging full PDFs since 2.0.0. This technique will only work with older versions.

The Solution

The solution is to specify the page range of the PDF. The documented behavior of the cat operation is to only preserve bookmarks when no page range is specified. It also confirms that A1-end will always include the entire PDF. Testing confirms that this purges the PDF of any bookmarks.

pdftk A=example.pdf cat A1-end output nobookmarks.pdf
Technologies:


blog comments powered by Disqus