bontus
bontus

Reputation: 537

Concatenate PDFs while preserving rank in list

I am currently struggling to concatenate my various PDF files into one file in an automated way while at the same time preserving the order the files are provided in. The main problem is, that I include a rank for each file (they are visualizations of list items), ranging currently from 1 to 100. If I run

pdftk *.pdf cat output all.pdf

the combined PDF pages will not be ordered from 1 to 100 accordingly. My PDFs are named in a similar way to the following example, please note that "rank_XXX" determines obviously their rank in the list. However, the fact that in the terminal 10 and 100 are listed prior to 2 messes up my sorting. I was thinking that ls -v could somehow be useful for pipe the filenames into pdftk or a similar tool, but I could not get it working.

I managed to get at least partially what I want by using

pdftk rank_[1-9]*.pdf cat output all.pdf

Nevertheless, this somehow does not work for numbers larger than 9.

Any help is greatly appreciated.

Upvotes: 1

Views: 234

Answers (1)

user897079
user897079

Reputation: 2945

ls -v seems to do the job:

pdftk `ls -v` cat output all.pdf

Upvotes: 1

Related Questions