Latest LQ Deal: Latest LQ Deals
Go Back > Blogs > sag47
User Name


Rate this Entry

Batch convert images to PDF

Posted 10-10-2010 at 05:48 AM by sag47
Updated 08-11-2011 at 01:10 AM by sag47

Recently (within the past year) I have helped a user with a problem converting hundreds of images into individual PDF files. I was pleasantly surprised to find imagemagick to effortlessly do this.

Command line tool imagemagick does what you need if they're images.
sudo apt-get install imagemagick
Usage: (coverts all images into one pdf)
convert *.jpg foo.pdf
Usage: (converts each image into an individual pdf)
This is if you want .jpg to be replaced with .pdf. This command will work with any image. Replace .jpg with whatever image extension you want.
IFS=$'\n';for x in `ls -w 1 *.jpg`;do convert $x `echo $x | sed 's/\.jpg$/.pdf/'`;done
Here is the previous command but a little simpler. This is if you want the file extension to be .jpg.pdf.
IFS=$'\n';for x in `ls -w 1 *.jpg`;do convert $x $x.pdf;done
Here's your bulk solution for converting all image files to pdf individually...
IFS=$'\n';for x in `ls -w 1 *.jpg *.jpeg *.png *.gif *.tif *.tiff`;do convert $x $x.pdf;done
As you can see with a little bit of terminal ninja scripting you can get the job done relatively effortlessly. (search shell script howto in google)
Posted in Uncategorized
Views 6455 Comments 1
« Prev     Main     Next »
Total Comments 1


  1. Old Comment
    My examples listed above are a pile of crap. Here's a better way of doing the above.

    For JPG images,
    for x in *.jpg;do convert "${x}" "${x%.jpg}.pdf";done
    The above example is better because it takes advantage of name globbing in bash for the *.jpg and when renaming the image to a PDF file it removes the .jpg extension first using bash parameter expansion.
    Posted 08-03-2013 at 09:50 AM by sag47 sag47 is offline


All times are GMT -5. The time now is 08:57 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration