You can easily list or extract all images from a PDF (or just from a specific page range) using the command line tool pdfimages
. This tool is available for Linux, Unix, Mac OS X and Windows.
pdfimages -list -f 3 -l 7 my.pdf
Above command lists all the images from page 3 (-f
"first") to page 7 (-l
"last") without extracting them.
The most recent versions of pdfimages
do even include additional info, such as width/height dimensions of the image, compression ratio, color space, bit depth, image encoding and resulting resolution as compared to the PDF page's own size:
kp@mbp:> pdfimages -list -f 3 -l 7 porsches-a4.pdf
page num type width height color comp bpc enc interp object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
3 0 image 1920 1440 rgb 3 8 jpeg no 20 0 175 175 182K 2.2%
4 1 image 1920 1440 rgb 3 8 jpeg no 26 0 175 175 130K 1.6%
5 2 image 1920 1440 rgb 3 8 jpeg no 32 0 175 175 92.1K 1.1%
6 3 image 1920 1440 rgb 3 8 jpeg no 38 0 175 175 233K 2.9%
7 4 image 1920 1440 rgb 3 8 jpeg no 44 0 175 175 238K 2.9%
To extract a specific page's images as JPEGs use the -j
parameter:
kp@mbp:> pdfimages -j -f 11 -l 11 porsches-a4.pdf prefix
This would extract all images from page 11. Their names would be prefix-000.jpg
, prefix-001.jpg
, prefix-002.jpg
etc.
NOTE: Sometimes direct extraction as JPEG isn't possible. pdfimages
will still extract them, albeit in PNM
or PPM
format. You can easily convert these to PNG or JPEG by using ImageMagick's convert
command:
convert some.ppm some.png
convert some.pnm some.jpg