Вопрос

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.

  • rank_1_XYZ_123123A.pdf
  • rank_1_XYZ_123123B.pdf
  • rank_2_XYZ_123141A.pdf
  • rank_2_XYZ_123141B.pdf
  • rank_3_ABC_394124A.pdf
  • rank_3_ABC_394124B.pdf ...
  • rank_10_XYZ_129123A.pdf
  • rank_10_XYZ_129123B.pdf ...
  • rank_100_ZZZ_929123A.pdf
  • rank_100_ZZZ_929123B.pdf

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.

Это было полезно?

Решение

ls -v seems to do the job:

pdftk `ls -v` cat output all.pdf
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top