0

I have installed ImageMagick on Windows 10. I can use it successfully from the command line to convert pdf to tiff or jpeg. If I try to use it from a php web page on the machine's Default Web Site via shell_exec() call it fails with the error message:

magick.exe: PDFDelegateFailed `[ghostscript library 9.27] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r300x300" "-sOutputFile=C:/Windows/TEMP/magick-10805W5t4T7R2ln8%d" "-fC:/Windows/TEMP/magick-10805T5PwK17wS3B" "-fC:/Windows/TEMP/magick-1080MMkVWJeXr8bF": (null)' @ error/pdf.c/ReadPDFImage/980.

<?php

$output=shell_exec('"C:\ImageMagick\magick" -density 300 "input.pdf"  "out.tiff" 2>&1');
echo "<pre>$output</pre>";

?>

hopefully helpful:

-shell_exec() is working in other contexts (runs other .exe files mkdir..) 
-I have given IUSR_xxxx (Internet Guest Account) permission to run magick.exe.
-the full pathname => "C:\ImageMagick\magick" 
PHP Version 7.2.14 
IIS version 1903(OS Build 18362.239) 
ImageMagick-7.0.8-53-Q16 
GPL Ghostscript 9.27 (2019-04-04)

Any ideas what the issue might be?

  • There could be several possible issues. First, you may not have Ghostscript installed where it can be found by Imagemagick. Second, but unlikely, GS 9.27 is reported to have some issues. Third, your hosting service may not allow shell_exec. Fourth, you may need to modify you Imagemagick policy.xml file to permit the reading of PDF files. See https://stackoverflow.com/questions/52861946/imagemagick-not-authorized-to-convert-pdf-to-an-image/52863413#52863413. I also do not see the usual `command=""gs"` to call Ghostscript in the command. Not sure how it works on Windows. – fmw42 Jul 14 '19 at 18:27
  • @fmw42 thanks u, what is the correct place for Ghostscript ! – saida lachgar Jul 15 '19 at 14:53
  • it work successfully from the command line – saida lachgar Jul 15 '19 at 14:55
  • and for hosting service, `shell_exec()` is working in other contexts like `mkdir..` & when i modified Imagemagick policy.xml file to permit the reading of PDF files nothing changed also the same error – saida lachgar Jul 15 '19 at 14:57
  • There are several places to modify the policy.xml file. Be sure to use the one at the highest priority that you can. – fmw42 Jul 15 '19 at 17:33
  • @fmw42 thanks for ur answers i found the solution ❤❤ – saida lachgar Jul 16 '19 at 10:32
  • https://stackoverflow.com/a/57043501/11259458 – saida lachgar Jul 16 '19 at 10:33

1 Answers1

0

✔ i found the solution ✨ just with using this code

1st convert .pdf to .tiff

$tif = "file.tif";
$pdf = "file.pdf";
$pdf2tif = "C:\gs\bin\gswin64c.exe -dNOPAUSE -r300 -sDEVICE=tiffscaled24 -sCompression=lzw -dBATCH -sOutputFile=$tif $pdf  2>&1"; 
shell_exec($pdf2tif);

then convert .tif to .text

$tif2txt = '"C:\OCR\tesseract" file.tif out -l fra  2>&1'; 
shell_exec($tif2txt);