I want to merge several hundred pdf files in a directory automatically according to their file names.
E.g.
The files
1000.1.pdf
1000.2.pdf
1000.3.pdf
1000.x.pdf should be merged into 1000.pdf
and
2000.abc.pdf
2000.def.pdf
2000.ghi.pdf
2000.jkl.pdf
2000.5.pdf into 2000.pdf.
I don’t want to use solutions based on Preview/Automator (if available) because compared to third party software like Adobe Acrobat or PDFpen merging pdf files often (depending on the source documents) results in a significant increase in file size (see e.g. What causes PDF file size to increase when saving in Preview?)
Do you have any recommendations? Thank you!
Best Answer
Try pdftk. It is command-line software that can join PDF files (and do lots of other stuff, too, but that isn't relevant here). You can download it from the official pdftk web page.
Sample syntax:
will create the file
new.pdf
that contains the concatenation of the filesold1.pdf
,old2.pdf
,old3.pdf
.To solve your problem, with your example filenames:
and so on. You can use shell scripting to make this completely automatic if desired (but you'll have to spend a little time on your own learning how to write shell scripts).
Assuming all files are named 1000.x, 2000.x etc. a shell script could look somehow like this