3

I have a list of files that I need to specify as input to pdftk so it will concatenate them in the order specified. I don't see an input file list as an option in the pdftk man page, but perhaps there's a workaround to achieve a similar result?

3
  • So you want to use the values from the list as the file names and the order in which they are to be concatenated, correct? Aug 29, 2017 at 21:59
  • @McDonald's Yes, correct. Aug 29, 2017 at 22:00
  • Not sure if it'll help with this or not but look over some of the answers here stackoverflow.com/questions/1521462/…. If it were Windows I could probably figure it out but I'm still learning Linux world and don't have anything to test with in front of me right now. Aug 29, 2017 at 22:05

1 Answer 1

6

This is described in the examples section of the man page:

Join in1.pdf and in2.pdf into a new PDF, out1.pdf:

    pdftk in1.pdf in2.pdf cat output out1.pdf

or (using handles):

    pdftk A=in1.pdf B=in2.pdf cat A B output out1.pdf

or (using wildcards):

    pdftk *.pdf cat output combined.pdf

Of course you can use shell or xargs to expand some list to the input pdf arguments...

Example for concat on all files specified in files.txt (assuming no issues with spaces in filenames etc.)

pdftk $(cat files.txt) cat output out.pdf
3
  • @user3188140 I've tried various permutations of combining xargs and pdftk without success, e.g.: xargs -I{} pdftk {} cat output result.pdf Aug 29, 2017 at 22:03
  • @JeffBauer: you could use: cat files.txt | xargs | xargs -I{} bash -c "eval pdftk {} cat output out.pdf" - but this construct has issues with spaces and command line length, too. Aug 29, 2017 at 22:45
  • 1
    With the addition of the last part of your reply $(cat files.txt), this becomes the accepted answer. Thanks for your help! Aug 30, 2017 at 21:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .