macOS: Convert PDF to PNG files for each page

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.