Converting jpeg to pdf with imagemagick and pdfjoin

Necessary files:

apt-get install pdfjam
apt-get install imagemagick

Script:

Quelle1)

#!/bin/bash
 
tempfiles=""
OUTPUT="jpg2pdf.pdf"
 
function die() {
	echo $*
	exit 1
}
 
for file in $*; do
	ext=${file##*.}
	base=`basename "$file" .$ext`
	pdf="/tmp/$base.pdf"
	echo "$file => $pdf"
	convert -rotate 90 "$file" "$pdf" 
	[ -e $pdf ] || die "Conversion to pdf failed"
	tempfiles="$tempfiles $pdf"
done;
 
pdfjoin $tempfiles --outfile jpg2pdf.pdf
[ -e $OUTPUT ] || die "Join of PDFs failed"
 
rm $tempfiles