There are a number of ways you can go about converting image files into PDFs, most simply by opening a given image and printing it. You can select “Print to file” instead of a printer device, then select PDF format and give it a name. But what to do if you have a folder full of images and want to make one big PDF of them? Here’s how you can do that:
convert *.jpg images.pdf
This creates a single PDF, images.pdf, containing all JPG files in the directory. It uses the very handy convert utility. Thanks to reader andreas for pointing out this much simpler approach!
[Edit, 2011-08-18] Thanks to reader A. Syukri for pointing out that the above approach can crash when there are too many input files. Here’s the longer approach that should be more stable:
FILES=$( find . -type f -name "*jpg" | cut -d/ -f 2)
mkdir temp && cd temp
for file in $FILES; do
BASE=$(echo $file | sed 's/.jpg//g');
convert ../$BASE.jpg $BASE.pdf;
pdftk *pdf cat output ../FINAL_NAME.pdf &&
rm -rf temp
This loops through all the .jpg images in the directory and converts them to a PDF file of the same name. Once that is done they are all combined into FINAL_NAME.pdf by pdftk, a handy PDF utility. The temp dir business is there to make the temp PDF file removal easier.
If you need to do this frequently you can create a bash function and pass in the folder containing the JPGs. You might want to also consider passing in the extension(s) desired if that varies for you.