4

There are answers by asalamon74 (here), and by anthon (here, here and here), that use pdftk.

I don't think I have pdftk installed on my ebook reader¹. How and where do I install it, and once installed how can I use it?


¹ This Q&A was inspired by this comment, which essentially could have been the above question. I did not find it appropriate to clobber each and every of my answers with installation and usage instructions for people that cannot seem to find those instructions using a search engine. Imagine the bloat that we would have if every answer with a reference to Calibre, Word or Open/Libre-office would have multiple paragraph about how to install such an application on each possible platform.

6

pdftk, the PDF toolkit, is a program that has been around since 2004, and is available for multiple platforms: Windows, Linux, OSX. Although you could probably compile (it is open source) and run it on some (Android based) ebook readers, it is more intended to be run on your main computer, to change files before loading them onto your ebook reader.

pdftk can do a lot of things out-of-the-box: collate scanned PDF pages (including handling reverse ordered back sides); decrypt and encrypt PDFs; joining and splitting of PDFs; removing of pages; rotating (90° increments) of pages; reporting on PDF metatdata and bookmarks.

pdftk is built on top of the iText java library. It's development history is documented by its revision history.

Installation

Windows

For Windows (XP, Vista, 7, 8), use the installer that you can get directly from the pdftk pages at PDF Labs. Run the executable installer, you should select the option [Don't create a Start Menu Folder]², but make sure you leave [Add application directory to your environment path] selected.

Now you can open the Command Prompt (in the "Accessories" program group) and type³:

pdftk --version

to make sure the program is correctly installed. You can now use the examples provided in the answers that were mentioned in the question.

OSX

You can download the Mac OS X installer (for Snow Leopard, Lion and Mountain Lion) from pdftk pages at PDF Labs, or use homebrew-cask as explained in this StackOverflow answer:

brew cask install pdftk

After that, open a Terminal and type

pdftk --version

to make sure the program is correctly installed. You can now use the examples provided in the answers that were mentioned in the question.

Linux

Most Linux distributions include pdftk, try

sudo apt-get install pdftk

or

sudo yum install pdftk

or pick another installer appropriate to the distribution.

After installation, open a terminal (if not already open for the installation process) or switch to a console (Ctrl+Alt+F1) and type:

pdftk --version

to make sure the program is correctly installed. You can now use the examples provided in the answers that were mentioned in the question.

Usage

pdftk is not hindered by a graphical user interface, therefore it is easy to automate repetitive tasks⁴. The examples in the answers, e.g.:

 pdftk *.pdf cat output ../combined.pdf

(to combine multiple PDF files in one file), can be copied and pasted from your web browser into your command prompt/terminal.

To find out about other easy ways to manipulate your PDF files, try:

pdftk --help

or have a look at the manual pages.

When in a hurry, and only having to do things once, it is sometimes easier to burst a while PDF into individual pages with:

pdftk in.pdf burst

then remove the pages you don't need anymore, or rearrange them by renaming them, and then combine them using:

pdftk pg_*.pdf cat output out.pdf

(this combines the pages in alphabetical order so if you want the original page 2 to go after page 3, just rename pg_0002.pdf to pg_0003a.pdf).

¹ If you don't mind doing repetitive tasks moving a mouse around, there is also a GUI based version of the program: PDFtk Free
² That only creates a superfluous entry in the Program menu with an Uninstall option, you can do that from the "Add/Remove Programs" in the Control Panel
³ If you are not familiar with using the commandline: you have to type the characters shown and at the end of the line press Enter
For instance by calling it from a batch file, a shell script or (my favourite) a Python program

  • Anthon, would you mind talking a bit about what pdftk does? You cover its history and how to install it, but not why I would want to install it or what I would do with it. Thanks! – Tom Mar 8 '14 at 7:42
  • @Tom That is a good idea, but I will try to add the highlights of the usage only, don't want to copy and paste the whole manual ;-). The history is less relevant here (IMHO), but I will try to find a link for those interested, OK? – Anthon Mar 8 '14 at 7:45
  • Sounds reasonable--definitely no need for the whole manual. Just a simple overview of what it does would be great! – Tom Mar 8 '14 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.