Thursday, June 11, 2009

Commandline PDF Manipulation

Want to do any of the following from a *NIX based system commandline with PDF documents:
  • Merge PDF Documents

  • Split PDF Pages into a New Document

  • Rotate PDF Pages or Documents

  • Decrypt Input as Necessary (Password Required)

  • Encrypt Output as Desired

  • Fill PDF Forms with FDF Data or XFDF Data and/or Flatten Forms

  • Apply a Background Watermark or a Foreground Stamp

  • Report on PDF Metrics such as Metadata, Bookmarks, and Page Labels

  • Update PDF Metadata

  • Attach Files to PDF Pages or the PDF Document

  • Unpack PDF Attachments

  • Burst a PDF Document into Single Pages

  • Uncompress and Re-Compress Page Streams

  • Repair Corrupted PDF

One way to accomplish any of these would be to use pdftk (PDF Toolkit).

Something I need to do quite often is concatenate (join) several PDF documents into one document. This can quite trivially be achieved with the following from the commandline:

$ pdftk 01.pdf 02.pdf cat output all_together_now.pdf

Above we concatenated 01.pdf and 02.pdf to form the new combined all_together_now.pdf document.


About Me

My photo
I love solving real-world problems with code and systems (web apps, distributed systems and all the bits and pieces in-between).