Edit/create a PDF’s Table of Contents with freeware

pdfpreviewsoftware-recommendationterminalunix

I have a PDF with a number of parts. I would like to create a Table of Contents to navigate the PDF with ease. I would like to do on a Mac this with freeware. (A command-line program would be great.)

Is that possible? Similar questions have been asked before, but as far as I can tell, the best answer given has been PDFOutliner, which is not freeware.

Best Answer

I found PDFtk Server and Coherent PDF Command Line Tools have a wide range of PDF command line utilities.

I've used both tools on and off, but never needed to do any TOC work. The Bookmarks section in Coherent's Usage Examples Page looks like it may be an approach to experiment with:

6. Bookmarks

cpdf -list-bookmarks in.pdf

List the bookmarks in in.pdf. This would produce:

0 "Part 1" 1 open
1 "Part 1A" 2
2 "Part 1B" 3
0 "Part 2" 4
1 "Part 2a" 5

cpdf -add-bookmarks bookmarks.txt in.pdf -o out.pdf

Add bookmarks in the same form from a prepared file bookmarks.txt to in.pdf, writing to out.pdf.