macOS: Convert PDF to PNG files for each page

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, October 19, 2016

Follow me on Twitter as @mattiasgeniar

I had to convert a long PDF to multiple PNG files, and it’s pretty easy with ghostscript at the terminal.

First, install Ghostscript using Homebrew.

$ brew install ghostscript

Next up, convert the PDF to PNG files.

$ gs -dNOPAUSE -sDEVICE=png16m -r256 -sOutputFile=page%03d.png input.pdf

A quick rundown:

  • -sDEVICE=png16m: the convertion to use, in this case convert to a 24-bit RGB color png file. If you value transparancy, use -sDEVICE=pngalpha.
  • -r256: the dimensions of your png file, the smaller the number, the smaller the size of your png’s. To give you an idea, -r256 comes down to 2816×2176 pixels.
  • -sOutputFile=page%03d.png: number each page of the PDF as “pageXXXX.png”, where XXXX is the number of the page.
  • input.pdf: the PDF you want to convert.

Good ol’ Ghostscript saves the day, yet again.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.