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 BlueSky

Newsletter

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

160: Graphs and RAGs explained and VS Code extension hacks Graphs and RAG explained, how AI is reshaping UI and work, how to efficiently use Cursor, VS Code extensions security issues.
159: AI pipelines, 10x faster TypeScript, How to interview How to use LLMs to help you write code and how much electricity does that use? Is your API secure? 10x faster TypeScript thanks to Go!
158: 🕹️ Super Mario AI 🔑 API keys in LLMs 🤙🏾 Vibe Coding Why is AI playing Super Mario? How is hallucinating the least of our worries and what are rules for developing Safety Critical Code?
157: CUDA in Python, Gemini Code Assist and back-dooring LLMs We met with a CUDA expert from NVIDIA about the future of hardware, we look at how AI fails and how to play pong on 140 browser tabs.
156: Enterprise dead, all about Bluesky and React moves on! Learn about Bluesky as a platform, how to build a React App and how to speed up SQL. And play an impossible game in the browser.

My other work: