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 · 6 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!

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

6 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.

Leave a Comment

(Don't forget to fill in the Captcha)

CAPTCHA image