Imagemagick安全策略似乎不允许我执行从pdf到png的转换。转换其他扩展似乎是工作的,只是不是从pdf。我没有改变任何imagemagick设置自从我安装它…我使用的是Arch Linux,如果操作系统很重要的话。

user@machine $ convert -density 300 -depth 8 -quality 90 input.pdf output.png
convert: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.
convert: no images defined `output.png' @ error/convert.c/ConvertImageCommand/3288.

当前回答

作为@Richard Kiefer的一个非常活跃的评论,一个简单的修复是这样的

$ sudo sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml

其他回答

在Ubuntu 19.10上,我在/etc/ imagemagick -6/policy.xml中完成了这个操作

取消这

<policy domain="module" rights="read | write" pattern="{PS,PDF,XPS}" />

评论一下

<!-- <policy domain="coder" rights="none" pattern="PDF" /> -->

在此之后,该命令正常工作,没有错误

convert -thumbnail x300 -background white -alpha remove sample.pdf sample.png 

为斯特凡·赛德尔的答案补充一点。

好吧,至少在Ubuntu 20.04.2 LTS或其他版本中,你不能以GUI方式直接编辑policy.xml文件。这里有一个终端的方式来编辑它。

在终端中输入“-”打开policy.xml文件 sudo nano /etc/ imagemagick -6/policy.xml 现在,直接在终端编辑文件,查找 <policy domain="coder" rights="none" pattern="PDF" /> 如图所示,将none替换为read|write。按“Ctrl+X”退出。

正如某些评论中指出的,您需要在/etc/ImageMagick-7/policy.xml中编辑ImageMagick的策略。更具体地说,在撰写本文时(05/01/2019),在ArchLinux中,以下一行是未注释的:

<policy domain="coder" rights="none" pattern="{PS,PS2,PS3,EPS,PDF,XPS}" />

只要在<!——和——>来注释它,PDF转换应该再次工作。

曼扎罗 2021 年 4 月

只需删除/etc/ imagemagick -7/policy.xml中<policymap>内未注释的行

对于Arch Linux的我来说,我不得不这样评论:

  <policy domain="delegate" rights="none" pattern="gs" />