I am working on a UNIX system and I\'d like to merge thousands of PDF files into one file in order to print it. I don\'t know how many pages they are in advance.
I\'
Here's the solution I use (it's based on @Dingo's basic principle, but uses an easier approach for the PDF manipulation):
First, I create a PDF file with a single blank page somewhere, e.g. in "/path/to/blank.pdf".
Then, from the directory that contains all my pdf files, I run a little script that appends the blank.pdf file to each pdf with an odd page number:
#!/bin/bash
for f in *.pdf; do
let npages=$(pdfinfo "$f"|grep 'Pages:'|awk '{print $2}')
let modulo="($npages %2)"
if [ $modulo -eq 1 ]; then
pdftk "$f" "/path/to/blank.pdf" output "aligned_$f"
else
cp "$f" "aligned_$f"
fi
done
Now, all "aligned_" files have even page numbers, and I can join them using
pdftk aligned_*.pdf output result.pdf