Convert folder of images to PDF with filenames

Programming Tutorials

Here is a shell script specific for GNU/Linux based operating systems to use. On different operating systems the convert commands will be the same, but the for loop will be different due to a different batch file syntax.

rm /tmp/imageex -r
mkdir /tmp/imageex
for filename in *.png; do
	echo "Processing $filename"
	convert $filename -background White \
		label:$filename -gravity Center \
		 -append -pointsize 14 \
		/tmp/imageex/$filename.png
done
echo "Exporting to PDF..."
convert /tmp/imageex/*.png output.pdf
echo "Done."