Medical Nerds Blog Logo
medicalnerds.com

technology, stats and IT for medics

 

Batch converting PDF to JPG/JPEG using free software

March 21st, 2007 by Mark · 40 Comments

imagemagick.pngIt is often necessary to batch convert PDF documents and graphics into other formats. I explain how to do this using totally free software. Searching for PDF software using Google is fraught with difficulty — one ends up with endless links to commercial sites, who charge lots of money, mislead users into paying for software that is similar to, or even uses free software. Freely available PDF software includes xpdf and ghostscript, and source code is fully available under a GNU GPL open source license.

I generate all my research graphics, charts, tables etc. using R. My semi-automated system for generating these using complex R scripts to fetch the latest data from PostgreSQL, perform analysis, and then generates PDF and Postscript files for inclusion into LaTeX documents. PDF is a great format, fully supported on the Mac, but Microsoft Word and Microsoft Powerpoint do not support PDF properly. This makes things very difficult, and while I prefer to use Apple’s Keynote program, presenting at scientific meetings tends to require Powerpoint.

Vector graphics are different to bitmap graphics, and tend to be smaller, and scale to both small and large sizes without becoming “jaggy”. Unfortunately, the standard vector file format for Microsoft applications is WMF (Windows Metafile), a proprietary and poorly documented standard, which means it is poorly supported by other operating systems, like Mac OS X and Linux. Even Microsoft’s own software on Mac OS X does not support WMF files properly, and often has difficulty importing documents using this format.

In an ideal world, Microsoft Powerpoint would support PDF graphics easily, but until it does, one needs to convert the files manually.

The best way at present appears to be to convert them to high-quality bitmap images. This involves rasterisation, and so does degrade quality, but I use a high “dots-per-inch” (DPI) when plotting, so that quality is maintained. I would recommend either 300 or 600.

Enter ImageMagick:

Installation on Microsoft Windows and Linux is easy. Either use your standard package manager, or download a binary from the ImageMagick website. ImageMagick actually uses ghostscript to do the rasterisation of the vector graphics, but provides a simpler user interface. For Mac OS X, I use MacPorts:


port install ImageMagick

Converting:

To convert one file:


convert -density 300 file.pdf file.jpg

To convert more than one file, one can use wildcards, such as *.jpg, but I prefer to use bash scripting (the default shell in Mac OS X) to batch convert files as it can preserve output filenames:


for i in `ls *.pdf`; do convert -density 300 "$i" "$i".jpg; done

And that’s it. You should end up with a directory of converted PDFs, suitable for inclusion into any Microsoft application!

Other formats
ImageMagick supports many other output file formats, including PNG, so try it out!


Update: June 2010

See a more recent post about a better way of converting multiple image files using mogrify.

Tags: Free · Graphics · LaTeX · Open Source · Software

40 responses so far ↓

  • 1 Bruce Williamson // Mar 7, 2008 at 3:18 pm

    Worked great. Glad I didn’t go buy some commercial junk.

  • 2 crimolvic // May 20, 2008 at 8:17 pm

    And what about making the files in the other direction? i.e. from JPG/PNG/BMP to PDF?

  • 3 John Tims // May 22, 2008 at 9:45 pm

    convert *.png test.pdf will put your images into a single pdf.

  • 4 radhakrishnan // Jun 17, 2008 at 6:09 am

    own use

  • 5 Phoenix // Jul 19, 2008 at 3:13 pm

    Hi. I would like to convert many JPEG files (about 500 in one folder) into one PDF file, where each page of the PDF is each JPEG file. Will ImageMagick allow me to do this? Thanks for any tips, and please email me if you respond. Thanks!

  • 6 pdfcreator // Aug 1, 2008 at 11:37 am

    Is a good aplication, and FREE, can convert pdf muti-pages in jpeg, one jpg per page !!!
    And can use how printer, than you use your aplication (word,mspaint,powerpoint) and convert in pdf only printing in a file.

  • 7 ga // Sep 21, 2008 at 6:47 pm

    Is a good aplication, and FREE

  • 8 coexisto // Oct 2, 2008 at 10:40 pm

    i can’t copnvert a pdf file in a jpeg file, i use linux and i wrote thios comand:

    convert -density 300 Mapa_General.pdf Mapa_General.jpg

  • 9 vicarious1 // Oct 19, 2008 at 12:32 am

    Hello I have 300.000+ scanned paper pictures and 100.000 digital pictures from BEFORE tagging became “In”. How can I start tagging “.jpg” in VISTA by folders or groups as I can’t imagine opening 300.000 pics and adding all the tags to each picture. it would take for ever.

  • 10 James // Oct 19, 2008 at 7:26 am

    What do you mean by tagging, is this a feature in Vista or your image manipulation program?

  • 11 emonk // Dec 4, 2008 at 5:51 pm

    very nice, thank you

  • 12 Jon Daley // Dec 5, 2008 at 9:41 pm

    Thanks – the -density option was the one I needed. -quality wasn’t helping much.

  • 13 GATOT // Jan 3, 2009 at 7:04 am

    i’ll try thanks

  • 14 S.C. Shaw // Feb 19, 2009 at 1:00 pm

    How can you make this statement about converting PDFs to JPGs: “For Mac OS X, I use MacPorts:”
    I have installed ImageMagick as described on their site on a MacBook UniBody Aluminum and the test of the logo conversion works fine after cmpleting installation. However, any attempt to convert PDFs is met with multiple error messages. In fact, in the CAFE of user questions they specifically state that ImageMagick DOES NOT support converting PDFs to JPGs!

  • 15 S.C. Shaw // Feb 20, 2009 at 12:16 am

    My bad. Needed to update Ghostscript. All works well now. Do not understand the CAFE response which stated that ImageMagick does not support converting PDFs to JPGs???

  • 16 Frank // Feb 20, 2009 at 8:57 am

    Hi,

    Convert is great but i noticed that font is not always properly converted. It looks like a problem of aliasing conversion. I did not see any parameter about that. Is anybody have the trick ?

  • 17 real estate // Mar 14, 2009 at 6:21 am

    Until I came upon this site I could only find freeware that did jpeg to pdf and not the other way around. This looks like it should solve my immediate need of turning a single pdf into a jpeg

  • 18 Andrey // Aug 19, 2009 at 10:19 am

    Guys, to allow IM converting PDF to any other format, don’t forget to install GhostScript.

  • 19 Chuck // Oct 7, 2009 at 4:43 pm

    Thanks for the excellent tip and for doing your part to make FOSS rise above the world of cruddy commercial software.

  • 20 mick mccrory // Dec 27, 2009 at 2:59 pm

    Is there a freeware solution to moving cad drawings from Adobe Reader pdf to some format that can be imported into a cad program so I can edit the drawing ?

  • 21 James // Jan 10, 2010 at 6:15 pm

    Google Inkscape

    BW

    James

  • 22 Sojwita // Jan 20, 2010 at 2:21 pm

    Thank you for presenting a command line solution. I have always used various command-line converters with biterscripting ( http://www.biterscripting.com ) . Here is a one of the scripts I use – convert all files created after Jan 1, 2010.

    var str list, file, name
    lf -n “*.pdf” > $list
    while ($list “”)
    do
    lex “1” $list > $file
    stex “^/^l[” $file > $file ; stex -p “]^.^l” $file > $name
    convert $file ($name+”.jpg”)
    done

  • 23 Tamas // Jan 27, 2010 at 10:12 am

    Try to use thier batch PDF to image (JPG, JPEG) batch conversion utility from http://www.fm-pdf.com, calledFM PDF To Image Converter Pro.

  • 24 Gestion // Jan 27, 2010 at 3:44 pm

    Google Inkscape

  • 25 arun // Feb 1, 2010 at 10:09 am

    i have installed imagemagic..and need to convert pdf to image file….but i can convert pdf file, which has only on page into jpg… but i cant convert the file which has multiple pages to image file

  • 26 TK // Mar 29, 2010 at 8:03 pm

    This page has good image conversion tips (also for pdf): http://www.linux.com/archive/feature/113978
    For multi-page pdf->image conversions you can use output file parameter like this: image_%04d.jpg
    That gives filenames image_0000.jpg image_0001.jpg …
    Change number 4 if you want shorter or longer ending length.

  • 27 Cullen Linn // Jun 4, 2010 at 6:29 pm

    Great information Mark and very helpful.

    Thank you!

  • 28 David Jameson // Jul 9, 2010 at 7:43 pm

    This loop does not work if the files have spaces in them. The $i seems to get the individual space delimited words rather than the entire filename without the .pdf

    for i in `ls *.pdf`; do convert -density 300 “$i” “$i”.jpg; done

  • 29 vetrivel // Aug 11, 2010 at 11:37 am

    this website very useful for our so…….. very good one.

  • 30 dyp // Jan 15, 2011 at 7:20 am

    GNU/Linux tools are great and free. why still with Microsoft and MacOSX ????

  • 31 LoMa // Jan 24, 2011 at 12:57 am

    simple and fast, the UNIX way 😉
    thank you !

  • 32 Helios // Mar 12, 2011 at 2:48 pm

    If the PDF file has bitmap images in it, then the source images can be extracted with pdfimages, which is a part of poppler-utils, which is better than converting the PDF file to bitmap.

  • 33 vl // Apr 13, 2011 at 7:11 am

    4Videosoft Free PDF to JPEG Converter is a free solution that batch converts your PDF documents to JPEG format.

    http://bstdownload.com/reviews/4videosoft-free-pdf-jpeg-converter-3/

  • 34 Michelle // Apr 16, 2011 at 12:36 am

    I am sorry, I have couldn’t understand any of this at all. I have no idea what to do. Is all I want is to change my word document into a pdf file so I can turn it into a downloadable book. I have wasted five hours and am still clueless. Everyone wants to charge so much money, I haven’t got a cent to spare. Even the trials, you can only convert a word doc to pdf only three to five pages – mine is a 300 page document. I think I am up the creek without a paddle.

  • 35 Reza Mosayebi // Apr 21, 2011 at 6:04 am

    Dear all,
    I need a program wich Converts JPEG to PDF with its source code in 5 days.Else I am going to be droped out of the research team .can u help me?

  • 36 vl // Apr 26, 2011 at 1:46 pm

    I use Okdo Pdf to Jpeg Converter to convert my PDF documents to JPEG images.

    http://bstdownload.com/reviews/okdo-pdf-jpeg-converter-4/

  • 37 Garry // May 4, 2011 at 9:34 am

    Michelle // Apr 16
    Google LibreOffice. Like M$ office, but better & free. Works on linux, mac, M$.
    Reads M$ garbage, prefers standards-compliant formats.
    Writes the same + PDF.

  • 38 camrynsmith // May 11, 2011 at 7:01 am

    Is there a freeware solution to moving cad drawings from Adobe Reader pdf to some format that can be imported into a cad program so I can edit the drawing ?

  • 39 Cae // Sep 5, 2011 at 11:30 pm

    tried out what you’ve suggested by the image quality is a little poor.

    this there an option to get higher resolution/quality of the output (jpg/png)?

  • 40 jobjol // Aug 19, 2012 at 6:13 am

    @ Cae, you need the density option. And maybe resize it afterwards.

Leave a Comment

(Don't forget to fill in the Captcha)

CAPTCHA image