How to execute ImageMagick to convert only the first page of a multi-page PDF to JPEG?

How to do ImageMagick convert if I want JPEG from the first page to consist of multi-page PDF?

+42
pdf imagemagick jpeg
Sep 27 '12 at 5:45
source share
3 answers

If you use the convert command line, you can execute it using these parameters:

 convert source.pdf[0] output.jpeg 

Note that the number of pages in ImageMagick is 0. Therefore, [0] means "page 1". To select, say, the 4th page, you will need to use [3] .

This syntax not only works for PDF input. It also works with other multi-page or multi-frame formats, such as multi-page TIFFs or animated multi-frame GIFs and PNGs.

+60
Sep 27 '12 at 5:48
source share

Do not use ImageMagick, use Ghostscript. ImageMagick encourages Ghostscript to do the work anyway ...

 gs -sDEVICE=jpeg -sOutputFile=<output-filename> -dLastPage=1 <input filename> 

You can also change the device to jpegcmyk (for CMYK output) or jpeggray for gray output, you can change the resolution with -r , use -dFirstPage and -dLastPage to extract a continuous range of pages, etc.

+10
Sep 27 '12 at 7:25
source share

To get an answer from @KenS, here are a few details, especially for Windows users.

You can download GhostScript for Windows here: http://www.ghostscript.com/download/gsdnld.html . The default installation path for the executable is "C: \ Program Files \ gs \ gs910 \ bin \ gswin64c.exe".

The command line arguments listed above are true on Windows as well, but here are some more useful tips:

 gswin64c.exe -dNOPAUSE -dBATCH -r96 -sDEVICE=jpeg -sOutputFile="<out-file.jpg>" -dFirstPage=1 -dLastPage=1 "<input-file.pdf>" 

I also created a batch file that wraps it well and sends it to my GitHub account. This makes it easy to create thumbnails for multiple .pdf files. Check it out at pdf2jpg.bat .

+3
Jan 31 '14 at 7:45
source share



All Articles