Search code examples
phplaravelimagemagickimagemagick-convert

Attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408


I am running a laravel project in my local ubuntu 20.04 machine that was functioning fine in another machine. The project uses Image Magic to convert PDF to PNG. While I am evoking the function to convert PDF into PNG I get the following error:

ImagickException attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408

THE function looks:

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'));
    }

SO far I have installed image magic and gs and made changes in policymap.xml with reference to the accepted answer of this question

Yet, the error persists. please help!

Thanks,


Solution

  • I also faced same issue, when I tried to parse pdf using pyocr

    wand.exceptions.PolicyError: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408
    

    To solve this issue, I edit policy.xml of ImageMagick-6. In that file, change the policy rights to read/write

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

    change to

    <policy domain="coder" rights="read|write" pattern="PDF" />
    

    If it doesn't solve your issue, you can also enable the below line in same file.

    <!-- <policy domain="module" rights="none" pattern="{PS,PDF,XPS}" /> -->
    

    change to

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