I want to convert pdf file to jpg. I installed imagick correctly and I installed ghoscript 9.53.3 64x but I got this error. I put the ghoscript / bin and lib path in the enviroment variable.
Fatal error: Uncaught ImagickException: PDFDelegateFailed `The system cannot find the file specified. ‘ @ error/pdf.c/ReadPDFImage/794 in C:xampp7.4htdocskOnlinevendorspatiepdf-to-imagesrcPdf.php:40 Stack trace: #0 C:xampp7.4htdocskOnlinevendorspatiepdf-to-imagesrcPdf.php(40): Imagick->pingimage(‘C:/xampp7.4/htd…’) #1 C:xampp7.4htdocskOnlinepdfToImaage.php(8): SpatiePdfToImagePdf->__construct(‘C:/xampp7.4/htd…’) #2 {main} thrown in C:xampp7.4htdocskOnlinevendorspatiepdf-to-imagesrcPdf.php on line 40
my code:
$pdf = new SpatiePdfToImagePdf($pathToPdf);
foreach (range(1, $pdf->getNumberOfPages()) as $pageNumber) {
$pdf->setPage($pageNumber);
$pdf->saveImage("Image_name".$pageNumber.".png");
}
PHP Version 7.4.11
Apache Version Apache/2.4.46 (Win64) OpenSSL/1.1.1g PHP/7.4.11
ghoscript 9.53.3 64x
imagick module version 3.4.4
OS windows 10 64x
5
Answers
I uninstalled
ghoscript 9.53.3
and installedghoscript 9.26
. I restarted the system after installation. That's all and my problem was solved.Had the same problem.
In older versions of ghostscript the executable was named "gs.exe", in newer versions it’s "gswin32c.exe" (or "gswin64c.exe"). I think somewhere the gs.exe-call is hard coded into the imagick-extension.
As workaround just rename the file to "gs.exe" or put a renamed copy in this directory.
I am using
gs9.54.0
Adding ghostscript path to the
PATH
, in my casec:softkitgsgs9.54.0bin
and renamegswin64.exe
togs.exe
solved this issue.It seems indeed that
imagick
is looking forgs.exe
1- Download from the site:
https://mlocati.github.io/articles/php-windows-imagick.html
if php 7.3: php_imagick-3.6.0-7.3-ts-vc15-x64.zip
if php 7.4: php_imagick-3.6.0-7.4-ts-vc15-x64.zip
if php 8.0: php_imagick-3.6.0-8.0-ts-vs16-x64.zip
2- Unzip the one that corresponds to the PHP version
A- take the DLL which is called: php_imagick.dll
and place it in the directory C:/laragon/bin/php/php-7.3.23-Win32-VC15-x64/ext
B- take all the other DLLs and put them in the directory C:/laragon/bin/php/php-7.3.23-Win32-VC15-x64
3- Open the PHP.ini file and insert the line where there are
The extensions precisely and write there:
extension = php_imagick.dll
4- Stop the APACH server and do a phpinfo(); to see
if the library is correctly installed with all
extensions possible
//////////////////////////
If you want to handle the PDFs from imagick continue the steps following
//////////////////////////
5- Then, you have to install the ghoscript software from
following url: https://www.ghostscript.com/releases/gsdnld.html
install the version that is going well x64 bit for example
6- Then, go to the directory
C:/Program Files/gs/gs9.55.0/bin
A- Duplicate the gswin64.exe file
B- Rename the copy to gs.exe
7- Add the directory C:/Program Files/gs/gs9.55.0/bin
in the PATH environment variables (users)
To do this, go to SEARCH WINDOWS and type env + enter
after go to environment variables and add
the missing directory
8- Super important, close the LARAGON software (completely)
Then turn it back on LARAGON and at this time, everything should function
I’m using the version provided in this link
And I had to downgrade my ghostscript to v5.26 and it worked. With the latest version of GS the server didn’t response.
Also you have to:
C:Program Filesgsgs9.25bingswin64.exe
gs.exe
C:Program Filesgsgs9.25bin
to the environment variablePATH
(maybe the installation path is other in your system).