Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.

hpr2667 :: Create PDF bookmarks with Pdftk

Basic intro to a few pdftk functions

<< First, < Previous, Latest >>

Hosted by klaatu on 2018-10-23 is flagged as Clean and is released under a CC-BY-SA license.
Tags: pdf.
Listen in ogg, spx, or mp3 format. | Comments (3)

Pdftk is a command that lets you manipulate PDFs outside of a GUI PDF creation tool. There are several GUI tools you can use to create PDFs with valid bookmarks and other fancy features, but pdftk is often more convenient.

Extract pages 1 through 2, and pages 5-21, and page 261 from a big PDF into a new PDF:

$ pdftk big.pdf cat 1-2 5-21 261 output small.pdf

Extract bookmarks from original PDF:

$ pdftk big.pdf dump_data output book.mark

Here is what a bookmark file looks like:

InfoKey: ModDate
InfoValue: D:20181010181951-05'00'
InfoKey: CreationDate
InfoValue: D:20181010181934-05'00'
InfoKey: Creator
InfoValue: pdftk (Linux)
InfoKey: Producer
InfoValue: pdftk 2.02-x86_64
PdfID0: d8deadbeeff34211ba60d80fda7611da
PdfID1: 39186170c6134566884b79c0ffee7d59
NumberOfPages: 261
BookmarkTitle: Cover
BookmarkLevel: 1
BookmarkPageNumber: 1
BookmarkTitle: Credits
BookmarkLevel: 1
BookmarkPageNumber: 2
BookmarkTitle: Chapter One
BookmarkLevel: 1
BookmarkPageNumber: 3
BookmarkTitle: Foo Section
BookmarkLevel: 2
BookmarkPageNumber: 5
BookmarkTitle: Bar Baz
BookmarkLevel: 3
BookmarkPageNumber: 7
BookmarkTitle: Back cover
BookmarkLevel: 1
BookmarkPageNumber: 19

Apply the bookmark data back to the PDF:

$ pdftk small.pdf update_info book.mark output final.pdf


Subscribe to the comments RSS feed.

Comment #1 posted on 2018-10-23T18:09:38Z by b-yeezi

gcj deprecated

It's a shame that PDFtk is basically going away because the GCJ runtime has been deprecated by most major distros. PDFTK still lives on as a Snap. Also, there is a fork that uses openJDK instead. You can reference this Stack Overflow post:

Comment #2 posted on 2018-10-24T00:59:02Z by Clinton Roy


I'm rather confused about why there's a reliance on any particular java runtime, but at least on debian, if i request pdftk to be installed, pdftk-java is installed, and yeah, no screwing around required.

Comment #3 posted on 2018-10-31T09:18:23Z by Klaatu

Thanks for the snap tip

I install and use pdftk on Slackware, so far without any issue. It's good to know about its availability in snap packages, though...just in case.

<< First, < Previous, Latest >>

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Anti Spam Question: What does the P in HPR stand for ?
Are you a spammer →
Who hosted this show →
What does HPR mean to you ?