My Little Experience with pdftk which saved my Golden time.

Ajit kumar
4 min readMay 8, 2018

PDFtk is a simple tool for doing everyday things with PDF documents. This article is about my little experience with pdftk on Ubuntu which saved my golden time during my Ph.D. thesis submission and re-submission.

On Monday, 7th May 2018, I defended my Ph.D. work and I wanted to share the little experience of using pdftk for preparing my thesis for printing. I used latex to write my Ph.D. thesis and kept the pdf output as a single pdf file. For printing my thesis, I have to go to a good printing shop which obviously used to be crowded and even more busy towards the end of the semester. Generally, for saving printing cost and to have better quality the printing shop use two different printers for black-and-white and color print. Selecting B/W or color during printing become tedious due to a large number of pages. So, quick and easy solution for a fast printing is to have two separate files for B/W and color printing. This also helps to save time waste at the shop which is very precious with a tight deadline.

With this requirement, I look many pdf processing tools for Ubuntu and found pdftk is very suitable for my purpose. Figure (below) shows the details options available in pdftk. I have very limited requirements so in this article only discusses important options.

Figure: Options available in pdftk.

Task 1: Filter the B/W and colors pages

So to achieve my goal, first I have to filter out the black-and-white and color pages. It could be done by going through each pages and noting down the page number to process with pdftk or any other tool. I had a different idea which emerged during learning pdftk basic commands. The pdftk has one option called “burst” which splits the input pdf file in all single page file with “page number” as filename. For example, below command is taking input_file.pdf as input and with burst options all it’s pages will become a pdf file.

$pdftak input_file.pdf burst

Figure: Pages from the input pdf as a single pdf file.

Now, one can ask, what is the benefit of splitting all pages and how it will help to filter the color and B/W pages. One can also think, printing individual page will take more time. So, answer to first that how splitting will help is that it need little hack from Ubuntu file thumbnail feature i.e. in Ubuntu and many other OS, files can be seen as list or as icon. So, if one see all the single pdf files as icon then it will easy to find out the color pages among all the files. For example, in below figure one can easily find out the color pages.

Figure: Icon view of files showing pages with colored items.

So, with this approach one can have two folder having B/W and color pages separately but as many single files. So, one need to look to create two single file one each for B/W and color.

Task 2: Merging many single pdf files to one pdf file.

There are many GUI tools for Windows and Ubuntu to merge pdf files but due to large number of files sometime it is difficult and I wanted to do it with command line with much ease. So, again I look pdftk for solution and I was surprise to know the options to merge multiple pdf file into one pdf file. Just to move the folder and execute below command.

$pdftk *.pdf cat output black-white-print.pdf

With above command all the single pdf files in the folder will be merge in sequence as a single pdf file.

  • .pdf : Tell pdftk to consider all the files in folder with .pdf file extension as input. It save time by not supplying files name explicitly.
  • cat : This option instruct pdftk to merge (concatenate) all the single pdf file to one pdf file.
  • output: This option indicates the resulting output file name.
  • black-white-print.pdf : The file name for the single merged pdfs.

With this, one will have two pdf files one for B/W print and other for color print. This saved me lot of golden time at the shop and shopkeeper like my approach because he have to spent very less time for printing my files. :)

This is just a slice of what pdftk can do for pdf manipulation. A detail tutorial can be helpful but that is for some other time. You can write me if you need any help with the use of tool.

I suggest interested user to go through below link to know the full capabilities of pdftk.

https://www.linux.com/learn/manipulating-pdfs-pdf-toolkit

--

--