Pdftk is a multiplatform command-line tool built on the iText library (which is described in iText for Java and C#). It has facilities for merging, splitting, and stamping documents, and for setting and reading metadata.
Pdftk has a somewhat unusual command-line interface, where elements often have to appear in a particular order. We can split them into four groups, in the order they are specified:
The input file or files, and possible input passwords.
The operation and any arguments it requires.
The output and any output passwords and permissions.
Sundry output and other options.
The full details can be found in the manual for pdftk—in this chapter, we give only the subset needed for our examples.
To merge documents, we use the
cat operation. This is the default operation, so
we don’t actually need to specify the
cat keyword. For example, to merge the pages of
three files into one, in order, we need:
pdftk file1.pdf file1.pdf file3.pdf output output.pdf
This writes a new file to output.pdf containing all the pages of file1.pdf, file2.pdf, and file3.pdf, in order. The output file may not be the same as any of the input ...