-1

hi i have a few thousand single paged pdf files in one folder and one single paged pdf(its file name is 2.pdf). I want to merge all the pdfs in the folder with the 2.pdf file. at the end should have all the pdfs in the folder with 2pages and the second page being the contents of 2.pdf. Please assist on this. thanks

1 Answers1

2

So for all PDF files of the current directory, except 2.pdf, we merge x.pdf with 2.pdf as a new file called new-x.pdf. So we can use the command given in merge / convert multiple pdf files into one pdf to do this:

cover="2.pdf";
outputDir="output-pdfs/";

mkdir "$outputDir";

for f in *.pdf; do
    [[ "$f" == "$cover" ]] && continue # skip the cover PDF
    pdfunite "$f" "$cover" output-pdfs/new-"$f".pdf;
done
Community
  • 1
  • 1
Édouard Lopez
  • 32,718
  • 23
  • 108
  • 161