Imagemagick Not Authorized to Convert Pdf to an Image

ImageMagick not authorized to convert PDF to an image

emcconville is correct. More specifically edit the Imagemagick policy.xml file to uncomment this line:

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



And change it from rights="none" to rights="read|write"

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



This was a recent addition to the policy.xml file, I believe, due to a security flaw found in the Ghostscript delegate. I think that flaw has now been fixed in the current version of Ghostscript, which is 9.25.

NOTE: On some systems the policy line will have domain="coder" rather than domain="module"

ImageMagick unable to convert PDF to images on WSL

You can find it like this:

identify -list configure | grep CONFIGURE_PATH

Failing that, use this search.

Failing that, use find in your WSL environment like this:

find / -name policy.xml 2> /dev/null

Failing that, just use Windows' Search to find a file calledpolicy.xml

How can I convert pdf to png now that imagemagik no longer works on my shared hosting server

I decided that getting policy.xml changed to allow pdf was not a good solution because it might just be overwritten at the next release and put me right back where I am. Research uncovered that ImageMagick uses Ghostscript to do the pdf conversions so why put up with an unreliable middleman. More research found some command line batch instructions to do the conversion. However, the resolution was terrible. Only when I got up to close to the resolution of 300 did I get good results but the file was huge. Ghostscript has a command that allows high internal resolution and then a downscale factor to bring the file to a smaller size. Why this is better than just directly converting to the file size I want is a mystery but this is the recommended solution and experimentation showed it to be of high quality. The final solution is as follows:

$gscommand = "gs -dNOPAUSE -dBATCH -r300 -dDownScaleFactor=3  -sDEVICE=png16m -sOutputFile=\"" .$file . "_%d.png\"  " . $file . ".pdf";
$returnedvalue = exec($gscommand);

In closing, this seems to be a pretty common problem without a solution other than use a different program. One recommended is pdftoppm which I did not find how to install on a shared host system and with Ghostscript doing the job there is no need to figure that out.

I hope this post helps others faced with this problem.



Related Topics



Leave a reply



Submit