macOS: Convert multi page PDF to multiple images by command

TLDR

  • Preview.app shall ONLY WORK with ONE PAGE.
  • Most commands on Stackoverflow shall ask you to use imagemagick : however recommended commands are for Linux which works different from macOS which is BSD-based.
  • Use this tried approach:

Approach

In terminal:

Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install imagemagick with Homebrew

brew install imagemagick

Add the following code to your ~/.bash_profile or ~/.zshrc depends on which shell you are using

function pdf2jpg () { convert +adjoin -verbose -background white -alpha remove -alpha off -density 300  $1 -quality 100 -sharpen 0x1.0 $1-%04d.jpg }
function pdf2jpgpw () { convert -authenticate $2 +adjoin -verbose -background white -alpha remove -alpha off -density 300  $1 -quality 100 -sharpen 0x1.0 $1-%04d.jpg }

Reload your shell or source ~/.bash_profile / source ~/.zshrc.

These commands can be called like

pdf2jpg xxx.pdf

which will generate a bunch of JPG files under the same folder; or, if the PDF is password protected,

pdf2jpg xxx.pdf password

will have the same effect.

Leave a Reply

Your email address will not be published. Required fields are marked *