Bala's Blog

PDF Toolkit

August 12 2017
150 words, ~1 min. read
pdf 

PDFtk is a simple yet effective tool for PDF.

encrypt document
pdftk <input>.pdf output <encrypted>.pdf encrypt_128bit owner_pw <owner-password> user_pw <user-password>
decrypt encrypted document
pdftk <encrypted>.pdf input_pw <password> output <decrypted>.pdf
combine multiple documents
pdftk <one>.pdf <two>.pdf cat output <output>.pdf
insert blank page
let's say if we have 1.pdf with 3 pages, 2.pdf with 5 pages and we need to combine into a new file with a sequence of all the pages in 1.pdf, a blank page and then the last two pages of 2.pdf,
$ pdftk F=1.pdf S=2.pdf B=blank.pdf cat F1-end B S4-5 output result.pdf
$ # or
$ pdftk F=1.pdf S=2.pdf B=blank.pdf cat F B S4-5 output result.pdf

Note: To create blank.pdf, use ghostscript or imagemagick as shown below,

  1. Use ps2pdf from ghostscript
$ touch blank.ps
$ ps2pdf blank.ps blank.pdf
  1. Use imagemagick
$ magick xc:none -page Letter blank.pdf

See also