0

---EDIT---

As discussed below and in the comments, my ISP took a default policy.xml on June 25 for Imagemagick which turns off convert for pdf files, which is what I need. I am getting crickets from my requests to modify it and I don't consider that a good solution as it could revert back on the next upgrade. I have found that Ghostscript will convert pdf files. I would appreciate any input if I am on the right track but so far this is very promising.

My existing call is this

convert -density 300 -quality 100 \"" . Aqualarm.pdf . "\"  -resize 800  -sharpen 0x1.0 -flatten \"" . Aqualarm.png  . "\"

The proposed Ghostscript version is this

gs -dNOPAUSE -dBATCH -r300 -dDownScaleFactor=3  -sDEVICE=png16m -sOutputFile="Aqualarm_%03d.png" Aqualarm.pdf

In this case Aqualarm is a test file.

---EDIT 2---

Using Ghostscript as described above worked with one modification. convert numbers files starting with 0 and gs numbers files starting with 1. I had to put a test in and if file 0 was missing, I changed the index to 1. Other than that I am happy with the result. This is apparently a common problem even on non shared host systems. The issue is that updates to ImageMagick will overwrite edits to the policy.xml so what you do there to make things work, might stop working on the next update. Since ImageMagick uses Ghostscript to do this anyway, I don't see any reason not to bypass the middleman.

From other reading I found that the reason ImageMagick disabled pdf by default is because of an error in Ghostscript that was fixed a few version back.

---END EDIT---

My website is on a shared hosting server. For years I have used ImageMagick "convert" to turn pdf documents into png. Now I get an error message as described here

ImageMagick security policy 'PDF' blocking conversion

The message is: convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.

The suggested solution is to modify policy.xml but of course on a shared host I do not have access to that file.

I have also seen the suggestion to install pdftoppm but even after hours of searching I cannot find out how to do that locally, without root access.

Is there a way that will work on a shared host server?

Thank you for reading.

Allen Edwards
  • 1,336
  • 1
  • 25
  • 43
  • Have you spoken to your hosts about it? You could always change hosts as it is a lot easier than it used to be. – Bonzo Jul 23 '20 at 20:13
  • I have placed two calls. The first guy said they don't support convert which is obviously not the case. The second woman escalated my case so at least didn't just blow me off. I am anticipating them saying that it is a security concern and they are not going to change it. They broke some other things recently which also look like they were done for security. Fixed those. Changing hosts would be much more trouble than solving this issue I am sure. My site is non trivial. Just changing php levels is a nightmare of support. – Allen Edwards Jul 23 '20 at 20:53
  • My ISP modified policy.xml on June 25. It has PDF files blocked. I would still like to install either ImageMagick or pdftoppm locally if I can.That would make me immune to them repeating this assuming I can even get them to change, which I doubt. – Allen Edwards Jul 24 '20 at 05:18
  • I do not use Imagick but it may be worth doing a test with that and see if that still works with pdf's, Imagick is an API for Imagemagick and is included in later versions of php. Check your php.ini file to see if it is installed. – Bonzo Jul 24 '20 at 07:13
  • I ran phpinfo() and there is no indication of Imagick. Interesting thing is that references php7.2/php.info and there is no such file on the system. Strange. Anyway, there were several php.info files and none says much at all and certainly nothing about Imagick. Not sure what else I can do to check that. I am running php7.2. – Allen Edwards Jul 24 '20 at 16:46
  • Try this: $version = Imagick::getVersion(); echo 'API version number: '.$version['versionNumber'].'
    '; echo 'API version string: '.$version['versionString'].'
    ';
    – Bonzo Jul 24 '20 at 17:25
  • @Bonzo. That produced an error Fatal error: Uncaught Error: Class 'Imagick' not found. I think I might be onto a solution though. ghostscipt was able to convert a small pdf to png although poorly. I assume I can add some parameters and perhaps do what I need. ---> gs -dNOPAUSE -dBATCH -sDEVICE=png16m -sOutputFile="Pic-%d.png" testing.pdf – Allen Edwards Jul 24 '20 at 21:15

1 Answers1

0

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.

Allen Edwards
  • 1,336
  • 1
  • 25
  • 43