A friend of mine recently asked me to upload a bunch of files to his Gallery. The gotcha was that a large number of images was provided in PDF format. Don’t even ask why or how or where or whatever. What was needed, however, was a way to convert hundreds of PDF files into jpegs. Fear not, xPDF is here!
Foolabs‘ wonderful contribution to PDF bliss includes a little utility called pdftoppm, which will render any PDF into images, one page at a time. The resulting format is a ppm image file, as understood by another open-source package, netpbm. It contains the aptly-named pnmtojpeg, which will take the ppm file to new levels of compatibility.
Ain’t it great? We’re all done here. I cobbled together a quick batch file, zipped it up with supporting files and sent it off to my friend. The complete solution:
- mkdir a directory on a drive somewhere. Call it pdf2jpg or whatever you like.
- Download xPDF from here. Extract pdftoppm.exe into your target directory.
- Download netpbm from here or here. Extract jpegxx.dll, libnetpbmxx.dll and pnmtojpeg.exe into said directory.
- Take the batch file below and write it to pdf2jpg.bat. in the same directory.
- Zip all this stuff up for future use.
- Dump all your PDF files into this same folder and double-click pdf2jpg.bat.
Keep in mind that this is a bare-bones set-up, intended only to convert PDFs containing images into jpeg files. It should work on most other PDF files as well, but expect error messages and potential rendering issues when attacking V1.6 PDFs (created by Acrobat 7), as well as warnings for missing fonts.
Please email me back any changes or improvements you made to this, and/or let me know how you’re using it.
The code:
@echo off
if "%1"=="" GOTO :DoAll
echo Processing %1
set file=%1
set file=%file:~0,-4%
set root=%CD%\%file%
pdftoppm -q -f 1 -l 1 -r 96 %file%.pdf "%root%"
pnmtojpeg < %file%-000001.ppm > %file%.jpg
del %file%-000001.ppm
GOTO :End
:DoAll
echo Searching for PDF Files
for %%A IN (*.pdf) DO CALL pdf2jpg.bat %%A
:End
Download this code: pdf2jpg.bat
|