Home » Bash, Linux Administration, Open Source

Bulk Export Images to JPG from PDF – bash one liner

19 October 2008 2 Comments

Sometimes I forget what power there is in free software. I put this quickie together the other day. Just be aware that it won’t handle any spaces in the PDF filename.

for i in *.pdf;do pdfimages $i ${i%.*};done && for i in *.ppm;do ppmtojpeg $i >> ${i%.*}.jpg;done; rm -f *.ppm

images are exported as -00n.jpg – ie: the n’th image found in the pdf.


  • greg said:

    it took me a while to figure out, but to handle spaces in filenames for that kind of bash-loop, you quote the second argument, it does not work with backtic args like: for i in `ls *gif`;

    for i in *.pdf; do pdfimages “$i” ; done

  • Nadine said:

    Wow – thanks for this! Exactly what I was looking for. I seemed to remember there being an export image function in Acrobat but couldn’t find it… Any way to have the images exported with a white background? (mine all had black ones).


Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.