如何使用Ghostscript或ImageMagick从PDF中提取图像?

时间:2013-06-12 12:16:52

标签: java imagemagick ghostscript

我需要渲染或获取特定PDF文件中的所有图像。如何使用Ghostscript或ImageMagick实现此目的?

3 个答案:

答案 0 :(得分:13)

您无法使用Ghostscript,但您可以使用名为pdfimages的Poppler或XPDF命令行工具执行此操作:

pdfimages -j some.pdf subdir/image-prefix

所有图片现在都位于subdir/ image-prefix-0001.jpgimage-prefix-0002.jpg ...

-j 参数会使命令尝试直接提取JPEG。如果无法创建JPEG,它将创建PNM或PPM,您可以使用ImageMagick进行转换:

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

答案 1 :(得分:1)

如果没有自己编写Ghostscript设备,你当然不能在Ghostscript中做到这一点 我怀疑你是否可以用ImageMagick做到这一点 你看过 PDFtk 吗?

如果您使用的是Windows,则可以快速启动Google:

http://www.somepdf.com/some-pdf-image-extract.html

在Linux上:

https://askubuntu.com/questions/150100/extracting-images-from-a-pdf

答案 2 :(得分:-1)

示例提取1页:

gs -q -dBATCH -dNOPAUSE -sDEVICE=pnggray -d300 -dFirstPage=1 -dLastPage=1 -sOutputFile=1.tiff in.pdf