Converting a multi page pdf to multiple pages using a single command

35,280

Solution 1

You're missing the quantity of digits. Use:

convert x.pdf x-%04d.jpg

Where 4 means 4 digits will be show on the page count.

Solution 2

If you use Graphicsmagick on Debian or ImageMagick on macOS you probably have to add ADJOIN to your command. So it should look like

convert x.pdf +adjoin x-%04d.jpg

Solution 3

When I tried to convert my multi-page pdf, the resulting image files had a gray background despite the pdf having a white background. (@John P commented on it on the accepted answer, but I couldn't get his comment to directly work for me.)

Here's what worked for me to make the background white:

convert -authenticate yourpassword -background white -alpha remove -alpha off -density 300 -quality 80 -verbose "Your file.pdf" "Your file.png"

My pdf had a password hence the authenticate. You can see a summary of the options here:

-authenticate value decipher image with this password

-background color background color

-alpha on, activate, off, deactivate, set, opaque, copy", transparent, extract, background, or shape the alpha channel

-density geometry horizontal and vertical density of the image

-quality value JPEG/MIFF/PNG compression level

-verbose print detailed information about the image

More detail: https://imagemagick.org/script/convert.php

And the alpha remove option: http://www.imagemagick.org/Usage/masking/#alpha_remove

Share:
35,280
Moiz Raja
Author by

Moiz Raja

Updated on May 17, 2020

Comments

  • Moiz Raja
    Moiz Raja about 4 years

    I want to convert multi page pdfs into single page images efficiently.

    I already know how to do this one page at a time with imagemagick. For example,

    convert x.pdf[2] x3.jpg
    

    will give me the 3rd page of the pdf as an image. So if I figure out how many pages are in the pdf using identify then I can loop through and convert all pages in the pdf to images. This method can however take a while. For example a 15 page pdf could take anywhere between 15-30 seconds.

    According to answers that I have seen elsewhere (also on the imagemagick forums) the following imagemagick command should split a pdf into multiple images.

    convert x.pdf x-%0d.jpg
    

    but all this ends up doing is creating the first page named x-0.jpg

    As an alternative I have tried using pdftk with the burst capability. The problem I faced there is that burst does not work in all cases. It does for some pdf's and does not for some others.

    Any suggestions on how to improve things would help.

    My OS is Mac OSX Lion but I do need this working on CentOS 6 as well.