Nice little bash loop to convert pdf to jpg


Using my scanner, I did a whole bunch of old pictures via the sheet feeder. Someday I'll post how I rev-engineered that device to run my custom scan handlers. These images aren't fantastic quality, but at least they are online and out of the box. The originals are safely sealed up in the crawl space. The scanner only feasibly does PDFs (with jpg compression, the irony). So this bash for loop that calls ImageMagick's "convert" is a handy way to split up the pdfs into a jpg per page.

for i in *.pdf;do echo $i
    convert -quality 100 $i `echo $i | sed -e 's/\.pdf/-%d\.jpg/g'`

It says for every PDF use convert at 100% JPEG quality. The nasty backtick echo at the end converts FILE.pdf to FILE-%d.jpg. %d is convert's way of numbering the pages. If you don't use %d you'll just get a single jpg from a multi page pdf.