3

I use PDFtk, and the PDF Chain gui. Despite reading the man page and investing time in a variety of web searches, I can't find the answer to this one -

I have a directory of PDF files, and I want to cat a common "cover sheet" PDF file on to each of them. So something like source1=../coversheet.pdf source2=*.pdf cat out*.pdf. (I know...)

Possible?

4

I would just run it in a loop, once for every pdf in the directory:

for f in *pdf; do 
    pdftk A=../coversheet.pdf B="$f" cat A1 B output "$f"_out.pdf;  
done

That will create a new file for each pdf with the cover page added. For a file called foo.pdf, it will create a new file called foo.pdf_out.pdf.

You can make this a bit more sophisticated. To create a file called foo_out.pdf use this instead:

for f in *pdf; do 
    name=$(basename "$f" .pdf); 
    pdftk A=../coversheet.pdf B="$name".pdf cat A1 B output "$name"_out.pdf; 
done

And, to overwrite the files with the new versions, use

for f in *pdf; do 
    pdftk A=../coversheet.pdf B="$f" cat A1 B output /tmp/tmp.pdf; 
    mv /tmp/tmp.pdf "$f"
done
  • The "unsophisticated" first option worked beautifully for me. Many thanks for this! Hope it will help others (like me!), too. ;) – Dɑvïd Aug 8 '14 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.