简体   繁体   中英

ImageMagick Errors: Reading PDF

I am on Win Server 2012 IIS 8, PHP 5.6, Imagick Module 3.1.2, ImageMagick 6.8.7-2 2013-10-18 Q16.

I have read through all the Postscript delegate failed errors and have done the following: - Installed GhostScript - Checked that GS and Imagick is in the PATH var - Checked that I can use convert in the command prompt (Does work) - PHP exec("whoami") returns nt authority\\iusr which I added for Full Control - I tried using full paths backslashes () double-backslashes (\\) foward-slashes (/) - I don't think it has anything to do with the path because if I try the same code on a jpg with no path it works. Script and files are in the same path.

Here is my PHP code:

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
echo exec("whoami"); echo "<br/>"; 
echo exec("convert.exe dr.pdf dr.jpg 2>&1"); // Does not work and gives below error
echo "<br/>";

$im = new imagick();        
$im->readimage("dr.pdf"); 
$pages = $im->getNumberImages();

echo $pages;

?>

Output:

nt authority\\iusr convert.exe: no images defined `dr.jpg' @ error/convert.c/ConvertImageCommand/3145.

Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `dr.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/682' in D:\\WWW\\DEMO\\data\\temp\\test.php:13 Stack trace: #0 D:\\WWW\\DEMO\\data\\temp\\test.php(13): Imagick->readimage('dr.pdf') #1 {main} thrown in D:\\WWW\\DEMO\\data\\temp\\test.php on line 13

Any help would be greatly appreciated. Regards Johan

To anyone who might run into the same problem: Change the permissions of C:\\Windows\\Temp to include Full Control for IIS_IUSRS and Users

After I did this everything seems to work!

Note: I had to upgrade to the latest PECL Imagick Module to see the full error that GhostScript was returning, which showed that GhostScript was trying to perform the conversion in windows Temp folder. It was strange that my php script worked from a command line but not from the website. But obviously it was a permission issue.

I'm posting the following Installation steps for whoever runs into the same problem (Or if I need a guide in the future and I forgot :) ) On Windows 2012 Server with IIS 8

  1. Install Win Platform Installer (https ://www.microsoft.com/web/downloads/platform.aspx)
  2. Go to IIS Manager and open Web Platform Installer and Install PHP 5.6
  3. Download ImageMagick x86 DLL install from here: http://www.imagemagick.org/download/binaries/ImageMagick-6.9.1-9-Q16-x86-dll.exe
  4. Install ImageMagick and ensure that $_SERVER["Path"] has the ImageMagick path configured.
  5. Download the latest PECL ImageMagick x86 NonThreadSafe PHP module here: http://windows.php.net/downloads/pecl/releases/imagick/3.3.0RC2/php_imagick-3.3.0rc2-5.6-nts-vc11-x86.zip
  6. Copy all the PECL ImageMagick DLL files into PHP\\ext
  7. Add extension=php_imagick.dll in your php.ini file
  8. Download and Install GhostScript x64 here: http: //downloads.ghostscript.com/public/gs916w64.exe (Not x86 as ImageMagick delegates to the 64bit GhostScript)
  9. Ensure that GhostScript Path is in $_SERVER["Path"] variable (C:\\Program Files\\gs\\gs9.16\\bin)
  10. IMPORTANT LAST STEP: Add user rights to C:\\Windows\\Temp for IIS_USRS and Users
  11. Restart Server (Usually required for PHP to see the paths)

What always helped me is testing my most basic script through a command prompt> php.exe test.php This will almost always show you errors if you did something wrong with the install or if you need a VC Redist. Where a website query doesn't always show you the startup errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM