使用图像魔术将pdf转换为图像并获取输出文件的列表



我找到了如何使用convert命令将我的pdf转换为png文件。这很棒,因为它开箱即用,可以为 pdf 中的每个页面创建一个图像,这正是我所需要的。问题是我事先不知道我的pdf有多少页,所以我不知道convert创建了多少页。我在互联网上看了又看,阅读了imagemagick网站,但找不到合适的方法来输出我需要的信息。

我需要一个非常简单的输出,如下所示:

$ convert in.pdf out.png
out-0.png
out-1.png
out-2.png
...

在 ImageMagick 中,只需执行以下操作:

identify in.pdf
in.pdf[0] PDF 256x256 256x256+0+0 16-bit sRGB 139350B 0.000u 0:00.002
in.pdf[1] PDF 256x256 256x256+0+0 16-bit sRGB 139350B 0.010u 0:00.001
in.pdf[2] PDF 256x256 256x256+0+0 16-bit sRGB 139350B 0.010u 0:00.000


或者,如果您只想要名称,那么

identify -format "%f[%p]n" in.pdf
in.pdf[0]
in.pdf[1]
in.pdf[2]


或者,如果您只想知道页数:

identify -format "%nn" in.pdf | head -n 1
3


注意没有管道到头,你会得到

3重复3次3次看

https://imagemagick.org/script/identify.php

https://imagemagick.org/script/escape.php

最新更新