Monday, May 7, 2012

Tip: Split selected pages from PDF document using Pdftk

Pdftk is a simple tool for manipulating PDF documents that runs in FreeBSD, Linux, Mac OS X, Solaris and Windows. With it the user can merge PDF documents, repair corrupted PDF, rotate PDF pages or document and extract selected pages from a PDF document creating a new document among other features.

BSD Magazine is a great and free magazine that deals with a wide range of BSD related subjects. The latest issue had a particular article that I felt I wanted to keep close to me.

Using Pdftk I was able to extract the pages that composed the article and keep it in a new PDF document.

Installing Pdftk on FreeBSD is a matter of changing to the print/pdftk port and issuing make install clean, like so:

  1. $ su
  2. # cd /usr/ports/print/pdftk
  3. # make install clean

Make sure to build lang/gcc46 with the JAVA Enable the Java frontend (i386 and amd64 only) OPTION selected or else the build process will fail (take it from me I learned it the hard way).

If you prefer to use packages instead of the ports tree, issue the following commands instead:

  1. $ su
  2. # pkg_add -r pdftk

Now for the fun part: using Pdftk on the this months' BSD Magazine as an example. Start by downloading BSD Magazine 5/2012 issue which you can find here.

I wanted to extract the Hardening FreeBSD with TrustedBSD and Mandatory Access Controls article which runs from page 46 to 49, this how to do it using Pdftk:
  1. $ pdftk 'BSD_05_2012.pdf' cat 46-49 output 'Hardening-FreeBSD-with-TrustedBSD-and-MAC.pdf'

You can find plenty of other uses for Pdftk in applications man page:
  1. $ man pdftk

No comments: