Do you want to password protect your pdf document? Do you want only selected pages from a document? Do you want to merge pages from different documents into one? Then,you have got to give Pdftk a try.
It’s a very handy command line tool to manipulate pdf documents. With pdftk,you can merge,split,rotate pdf documents,burst a pdf document into separate pages and you can even encrypt your documents.
It is available for a variety of platforms including Linux,Mac OS X,Windows,Free BSD and Solaris.
To install pdftk on Debian or Ubuntu, simply fire up a terminal and type:
sudo apt-get install pdftk
To install on other distributions or other OS, please see here.
PERFORMING TASKS WITH PDFTK
Before you type the commands,make sure you are in the directory where your documents are present. If you are performing operations that take two documents as input,make sure that both of them lie in the same directory.
Let’s say, we have two documents gnome.pdf and kde.pdf in ~/Downloads directory.
Splitting selected pages from a single document
To split pages 3,6 and 9 from gnome.pdf and combine them into a new document named xfce.pdf,open a terminal and type:
pdftk A=gnome.pdf cat A3 A6 A9 output xfce.pdf
If everything goes well, xfce.pdf will be created in the same directory. However you WON’T get any information on the terminal stating that your document has been generated.
You can see in the figure above that after executing the command, I didn’t get any information, whatsoever. But if there is any error, it will be displayed.
Splitting selected pages from multiple documents and combining them into one
To split pages 3-7 from gnome.pdf and pages 5-8 from kde.pdf and combine them into a single document called xfce.pdf, type:
pdftk A=gnome.pdf B=kde.pdf cat A3-7 B5-8 output xfce.pdf
Merging two documents into one
To merge gnome.pdf and kde.pdf into a single document xfce.pdf,type:
pdftk A=gnome.pdf B=kde.pdf cat A B output xfce.pdf
Bursting all the pages of a document
To burst all the pages of gnome.pdf,type:
pdftk gnome.pdf burst
This will generate ‘x’ number of pdf document with names pg_0001.pdf to pg_000x.pdf where ‘x’ is the number of pages in the document.
Password protecting your document (best feature!!)
To encrypt and password protect gnome.pdf with password “linux”,type:
pdftk gnome.pdf output gnome.128.pdf owner_pw foo user_pw linux
This will generate a gnome.128.pdf document which will be password protected.
These are the functions that I use frequently.For a complete list of functions click here.