How do I execute ImageMagick's convert
if I want a JPEG from the first page only of a multi-page PDF?
If you are using a convert
command line you can execute it with these parameters:
convert source.pdf[0] output.jpeg
Note that the page count of ImageMagick is 0-based. So [0]
means 'page 1'. To select, say the 4th page, you'd have to use [3]
.
This syntax does not only work for PDF input. It also works with other multi-page or mult-frame formats, such as multi-page TIFF or animated multi-frame GIFs and PNGs.
source.pdf[0-3]
. –
Jiggermast [1]
, so it starts counting at 0. ImageMagick version 7.0.7-33, GraphicsMagick version 1.3.29. –
Boneset [3,2,4]
-- documentation: "Selecting Frames" section of imagemagick.org/script/command-line-processing.php#input . –
Balakirev convert 'source.pdf[0]' output.jpeg
. –
Shakedown Don't use ImageMagick, use Ghostscript. ImageMagick calls 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 using -r
, use -dFirstPage
and -dLastPage
to extract a continuous range of pages, etc.
-sDEVICE=png16m -r300 -dDownScaleFactor=4
–
Vestiary To further the answer by @KenS, Here are a more few details, particularly 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 correct in Windows too, but here are a few more that I found useful:
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 this up nicely and posted it to my GitHub account. It makes it a lot easier to create thumbnails for multiple .pdf files too. Check it out at pdf2jpg.bat.
%d and some other qualifiers to nummerate output using ghostscript wont work with latest versions as they did with older versions.
© 2022 - 2024 — McMap. All rights reserved.