How to merge PDF files with the same file prefix?

1

I have a lot pdf files (~30.000) with following name structure:

number1_1.pdf
number1_2.pdf
number1_3.pdf

number2_1.pdf
number2_2.pdf

number3_1.pdf
number3_2.pdf
number3_3.pdf
number3_4.pdf

and I need to combine files with the same file prefix into one pdf:

{number1_1.pdf,number1_2.pdf,number1_3.pdf} = number1.pdf
{number2_1.pdf,number2_2.pdf} = number2.pdf
{number3_1.pdf,number3_2.pdf,number3_3.pdf,number3_4.pdf} = number3.pdf

What is the best/easiest way how to do it on a Windows machine?

richi

Posted 2016-03-15T07:30:05.480

Reputation: 11

Easy way: A script that will do this for you. – Teo – 2016-03-15T08:12:11.783

Answers

1

Sejda console can help you merge the files that start with a specific prefix:

bin/sejda-console.bat merge -d C:/Downloads --matchingRegEx "number1_(.*).pdf" -o C:/number1.pdf

Sejda is an open source tool for manipulating PDF files. I'm one of the devs.

Edi

Posted 2016-03-15T07:30:05.480

Reputation: 532

Thank you, I really didn't know Sejda. Your solution is just for one set/prefix, but how can I automatically run it over the whole collection under a directory? – richi – 2016-03-16T13:42:23.313

I'm not experienced with Windows scripting, but here's how I would do it in Unix: ls *_*.pdf | cut -d '_' -f 1 | uniq | xargs -I 'bin/sejda-console merge -d ~/Downloads --matchingRegEx "{}_(.*).pdf" -o /tmp/{}.pdf' – Edi – 2016-03-18T13:52:25.803