I need to render or fetch all the images from a specific PDF file. How can I achieve this using Ghostscript or ImageMagick ?
The ghostscript interpreter is used by ImageMagick and GraphicsMagick to convert Postscript and similar formats into images.
Use ImageMagick® to create, edit, compose, or convert digital images. It can read and write images in a variety of formats (over 200) including PNG, JPEG, GIF, WebP, HEIC, SVG, PDF, DPX, EXR and TIFF.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With