How to extract images from PDF using Ghostscript or ImageMagick?

user1283633 picture user1283633 · Jun 12, 2013 · Viewed 9.6k times · Source

I need to render or fetch all the images from a specific PDF file. How can I achieve this using Ghostscript or ImageMagick ?

Answer

Kurt Pfeifle picture Kurt Pfeifle · Jun 24, 2013

You cannot do it with Ghostscript, but you can do it with Poppler's or XPDF's commandline tools named pdfimages:

pdfimages -j some.pdf subdir/image-prefix

All the images will now be located in subdir/ named image-prefix-0001.jpg, image-prefix-0002.jpg ...

The -j parameter will make the command try to directly extract JPEGs. Failing to create JPEGs, it will create PNMs or PPMs, which you can always convert using ImageMagick:

convert subdir/image-prefix-0033.ppm subdir/image-prefix-0033.jpeg