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
Why Is Reading Lines from Stdin Much Slower in C++ Than Python
How to Set the 'Backend' in Matplotlib in Python
Get Total Physical Memory in Python
Do Python Regular Expressions Have an Equivalent to Ruby'S Atomic Grouping
Converting String "Jun 1 2005 1:33Pm" into Datetime
Accessing the Index in 'For' Loops
Convert a String Representation of a Dictionary to a Dictionary
Difference Between @Staticmethod and @Classmethod
How to Replace Multiple Substrings of a String
How to Match a Whole Word With a Regular Expression
Is There Go Up Line Character? (Opposite of \N)
How to Make a Python Script Run Like a Service or Daemon in Linux
How Would I Build Python Myself from Source Code on Ubuntu
Why Do Some Regex Engines Match .* Twice in a Single Input String
Strange Result When Removing Item from a List While Iterating Over It
How to Iterate Over a List in Chunks
How to Split a String into a List
Get Statistics For Each Group (Such as Count, Mean, etc) Using Pandas Groupby