我需要渲染或提取特定PDF文件中的所有图像。如何使用Ghostscript或ImageMagick实现这一目标?
我需要渲染或提取特定PDF文件中的所有图像。如何使用Ghostscript或ImageMagick实现这一目标?
pdfimages
来实现:pdfimages -j some.pdf subdir/image-prefix
subdir/
的目录中,命名格式为 image-prefix-0001.jpg
、image-prefix-0002.jpg
...。-j
参数可以尝试直接提取JPEG。如果无法创建JPEG,则会创建PNM或PPM文件,您始终可以使用ImageMagick进行转换:convert subdir/image-prefix-0033.ppm subdir/image-prefix-0033.jpeg
convert some.pdf image-prefix.jpg
- patxiskaconvert
将 PDF 页面转换为包含页面文本部分的全页图像;而 pdfimages
则提取嵌入在 PDF 页面中的图像,而不包括文本部分。) - Kurt Pfeiflehttp://www.somepdf.com/some-pdf-image-extract.html
在Linux上:https://askubuntu.com/questions/150100/extracting-images-from-a-pdf
ImageMagick还提供了以下语法选项,将PDF转换为图像:
convert /path/to/file.pdf /path/to/output/file.png
除了“常规”转换外,它还提供了许多有用的选项,例如:
[0-n]
,例如convert "file.pdf[0-1]" /path/to/output/file.png
)-define pdf:use-cropbox=true
-density 300
-resize 2000x2000>
-background white
-alpha remove -alpha off
等等。
例如提取1页:
gs -q -dBATCH -dNOPAUSE -sDEVICE=pnggray -d300 -dFirstPage=1 -dLastPage=1 -sOutputFile=1.tiff in.pdf