First install ImageMagick
Run the following commands:
mogrify -resize 663x1024 *.jpg
for i in `seq 0 26`; do convert $(printf "filename-%03d" $i).jpg $(printf "filename-%03d" $i).pdf; done
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=temp.pdf $(for i in `seq 0 26`; do printf "filename-%03d.pdf " $i; done)