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:
1 2 | cd FOLDER_WITH_IMAGES 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:
1 2 3 4 5 6 7 8 9 10 | cd FOLDER_WITH_IMAGES 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; done && pdftk *pdf cat output ../FINAL_NAME.pdf && cd .. 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.
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.









It worked very very well!
I had problems with the “convert” (from imagemagick) because it makes my computer run out of memory when I want to convert a lot of image files into one pdf. This seems to solve the problem. I just wich I could understand all the those BASE=$ commands. lol
@Montebelo I’m glad it worked for you! Actually that command probably looks trickier than it is. The for loop iterates over each item in the FILES variable (i.e. all the image files we want to convert). For each item BASE is set to the image filename with the extension (“.jpg”) stripped. This is so we can title our output the same as the original. In the convert step, we use BASE to specify what image to convert and also what to call the resultant PDF. Hope that helps!
what about the single line:
convert *.jpg figures.pdf;
or am I missing something here?
take care
@andreas Your invocation works perfectly well. I cannot fathom right now why I made it so complicated! The only reason I needed a temp folder was to deal with the intermediate PDFs, which I don’t at all need as your example shows. I’ll rework the post shortly, thanks very much for the correction!
Because the one-liner will crash when handling too many files as input. Can you please show again the original commands you used that @montebelo said was working?
@A. Syukri: Thanks for reporting that! I’ve added the older version into the post.
Note: It doesn’t handle case-variability in file extensions right now, so will try to add that soon.
Amazing!
The quality of pdf generated by this method is too poor.Though many people might have not noticed it.You can check this thread here
http://askubuntu.com/questions/95136/converting-images-to-pdf-without-quality-loss/95189#comment108998_95189
Thanks, Abhishek D.
The result was much better using convert’s option -quality 100 .
Linux is great! It’s just the convert command I looked for. Thanks…