Christian Heilmann

Quick one: converting a multi-page PDF to a JPG for each page on OSX

Sunday, September 30th, 2012 at 1:38 pm

I had this great task to convert a PDF to JPGs, meaning a multi page PDF should become a lot of JPGs. I don’t own Adobe Acrobat Pro and I didn’t want to buy an extra piece of software for it. So I went for the thing that hardly ever lets you down – even it it speaks in tongues – the command line.

So here is how to convert a PDF to JPGs:

Install homebrew by going to the terminal and copying and pasting the following:

ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

The script explains what it does while it runs. It is not the matrix, although it is green and full of text.

Next get Ghostscript – just go to the command line and do a:

brew install ghostscript

This can take a while, so get a cuppa on. Once you are done, here’s the command to convert a PDF to a lot of JPGs:

gs -dNOPAUSE -sDEVICE=jpeg -r144 -sOutputFile=p%03d.jpg file.pdf

The PDF is file.pdf and this will generate files called “p001.jpg” to “p004.jpg” for a 4 page document for example. You can change that with the p%03d.jpg setting above. For example plonk%04d.jpg would create plonk0001.jpg.

Once the conversion is done you are in the GS> prompt, just press Ctrl+C to get out.

Share on Mastodon (needs instance)

Share on Twitter

Newsletter

Check out the Dev Digest Newsletter I write every week for WeAreDevelopers. Latest issues:

Dev Digest 146: 🥱 React fatigue 📊 Query anything with SQL 🧠 AI News

Why it may not be needed to learn React, why Deepfake masks will be a big problem and your spirit animal in body fat! 

Dev Digest 147: Free Copilot! Panel: AI and devs! RTO is bad! Pi plays!

Free Copilot! Experts discuss what AI means for devs. Don't trust containers. Mandated RTO means brain drain. And Pi plays Pokemon!

Dev Digest 148: Behind the scenes of Dev Digest & end of the year reports.

In 50 editions of Dev Digest we gave you 2081 resources. Join us in looking back and learn about all the trends this year.

Dev Digest 149: Wordpress break, VW tracking leak, ChatGPT vs Google.

Slowly starting 2025 we look at ChatGPT vs Google, Copilot vs. Cursor and the state of AI crawlers to replace web search…

Dev Digest 150: Shifting manually to AI.

Manual coding is becoming less of a skill. How can we ensure the quality of generated code? Also, unpacking an APK can get you an AI model.

My other work: