curly
curly

Reputation: 43

merge pdf files by string in filename using ubuntu terminal

I have a large number of pdfs that need to be merged into files of 2-3 pages according to their titles.

For example if I had the following files;

jim_contract1.pdf
jim_contract2.pdf
jim_contract3.pdf
susie_contract1.pdf
susie_contract2.pdf
charlescontract1.pdf
charlescontract2.pdf
charlescontract3.pdf
charlescontract4.pdf

I want to be able to write a line of code for each group to merge the files to have the result

jim_contract_merged.pdf
susie_contract_merged.pdf
charlescontract_merged.pdf

I tried to use this code:

pdftk 'find -type f -name 'jim_contract*'' cat output jim_contract_merged.pdf

But it only returns an error message.

Is there a way to do this from the terminal?

Upvotes: 1

Views: 6110

Answers (1)

Drasz
Drasz

Reputation: 41

Try the following:

pdfunite 1.pdf 2.pdf n.pdf out.pdf

So in your case you could try

pdfunite jim_contract*.pdf jim_contract_merged.pdf

Or if you don't have the pfdunite command, try ghostscript:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=jim_contract_merged.pdf jim_contract*.pdf

Upvotes: 2

Related Questions