utilities  

Aug 19, 2014 • Michael Chen

Coherent PDF Tools is a command line PDF tool for Windows, Mac and Unix. It is free for non-commercial use. I wanted to remove all bookmarks in the PDF file and re-edit them and Coherent PDF Tools can remove all bookmarks in single command. After some try, it simply worked. Here I introduce how to edit bookmarks with Coherent PDF Tools. This tutorial was tested on OS X 10.9.

Coherent PDF Tools is a single command line tool without external dependency, so just download the binary release and put it into execution path like /usr/local/bin.

Before editing bookmarks, dump out the bookmark file.

$ cpdf -list-bookmarks input.pdf > bookmarks.txt

bookmarks.txt is a plain text file, the format looks like the following content:

0 "Cover" 0
0 "Chapter 1" 10
1 "1.1 Introduction" 10
1 "1.2 Get Help" 12
0 "Chapter 2" 16

Each single line presents one bookmark in PDF file. The first part means the hierarchy of bookmarks. The next bookmark should only be one layer deeper than the previous bookmark. The second part is the bookmark text showed in a PDF file. Text should be quoted with double quotation marks and no inner double quotation marks are allowed. cpdf seems unable to escape double quotation marks. The final part is the page of the bookmark. Page number should be counted from the cover page and started from 1.

After editing bookmarks.txt, save back to the PDF file:

$ cpdf -add-bookmarks bookmarks.txt input.pdf -o output.pdf

If any error occurs, the step will not succeed. Check bookmarks.txt for possible errors.

If you intend to delete all bookmarks on a PDF file, do this:

$ cpdf -remove-bookmarks input.pdf -o output.pdf

There are a lot thing can be done with Coherent PDF Tools, see their manual for the details.