Skip to content

Concatenating PDFs from CLI

January 13, 2010

The widely known and easiest way to combine PDF documents from the command line is to use pdftk:

$ pdftk file1.pdf [file2.pdf ...] cat output dest.pdf

pdftk can do a lot more than just pdf concatenation. It can also split pages, rotate pages, apply watermarks and even repair broken PDFs. The downside is it removes outlines or bookmarks from the output document. So if you need the bookmarks intact you can’t use pdftk.

If you only need simple concatenation with bookmarks, use iText. iText is a powerful Java library for PDF generation and manipulation. Thankfully we don’t need to write our own Java code since hidden underneath is a simple PDF concatenation tool:

$ java f1.pdf [f2.pdf ...] \

Besides ConcatPdf, iText also has other tools such as SplitPdf and HandoutPdf.

iText in Ubuntu How To

To install iText in Ubuntu/Debian, from Synaptic install the package “libitext-java”. If you prefer the command line:

$ sudo apt-get install libitext-java

Before using iText like the above example you need to set up the CLASSPATH:

$ export CLASSPATH=$CLASSPATH:/usr/share/java/itext.jar

Or you can also set the CLASSPATH directly:

$ java -cp /usr/share/java/itext.jar \ f1.pdf [f2.pdf ...] dest.pdf
One Comment
  1. Qoppa Software offers java tools to merge and concatenate PDF documents:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: