![](/img/trans.png)
[英]Uncaught ImagickException: attempt to perform an operation not allowed by the security policy `PDF'
[英]Attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408
我在本地 ubuntu 20.04 机器上运行一个 laravel 项目,该项目在另一台机器上运行良好。 该项目使用 Image Magic 将 PDF 转换为 PNG。 当我调用 function 将 PDF 转换为 PNG 时,出现以下错误:
ImagickException 尝试执行安全策略“PDF”不允许的操作@error/constitute.c/IsCoderAuthorized/408
function 看起来:
public function show($id)
{
$book = Book::all()->first();
$file = public_path('' . $book->pdf);
$count = 0;
$im = new \Imagick($file);
$blobList=[];
do {
$page = new \Imagick();
$page->setResolution(300,300);
$page->readImage($file . '['.$count.']');
$page->setImageFormat("jpeg");
header("Content-Type: image/jpeg");
$image = $page->getImageBlob();
array_push($blobList,$image);
$count++;
} while (5> $count);
// $im->resizeImage(200,200,1,0);
return view('notice/showbook', compact('book', 'blobList'));
}
到目前为止,我已经安装了 image magic 和 gs,并参考这个问题的公认答案在policymap.xml
中进行了更改
然而,错误仍然存在。 请帮忙!
谢谢,
当我尝试使用 pyocr 解析 pdf 时,我也遇到了同样的问题
wand.exceptions.PolicyError: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408
为了解决这个问题,我编辑了 ImageMagick-6 的 policy.xml。 在该文件中,将策略权限更改为读/写
<policy domain="coder" rights="none" pattern="PDF" />
改成
<policy domain="coder" rights="read|write" pattern="PDF" />
如果它不能解决您的问题,您还可以在同一文件中启用以下行。
<!-- <policy domain="module" rights="none" pattern="{PS,PDF,XPS}" /> -->
改成
<policy domain="module" rights="read|write" pattern="{PS,PDF,XPS}" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.