PHP: Uncaught ImagickException: PDFDelegateFailed
Asked Answered
B

4

6

I want to generate images from pdf pages in PHP. I am using imagick php extention to achieve this but I am getting error below when i am tring to read pdf file by imagick

Fatal error: Uncaught ImagickException: PDFDelegateFailed `The system cannot find the file specified. ' @ error/pdf.c/ReadPDFImage/801

My code is

$imagick = new Imagick();
$imagick->readImage(dirname(__FILE__). '/test.pdf'); 

My Server details from phpinfo()

PHP: Version 7.0.13
System: Windows NT LALMANI-PC 6.1 build 7601 (Windows 7 Ultimate Edition Service Pack 1) i586, Architecture: x86
imagick module version: 3.4.3
Imagick using ImageMagick library version: ImageMagick 6.9.3-7 Q16 x86

I also installed ImageMagick-6.9.9-27 and Ghostscript 9.22 in my system.

Please let me know what is wrong here. Thanks in advance.

Bathilda answered 25/12, 2017 at 14:8 Comment(0)
B
5

I got issue in Ghostscript 9.22 installation that was 64-bit, I uninstalled that and installed Ghostscript 9.22 32-bit. Issue Fixed.

Thanks for your help.

Bathilda answered 26/12, 2017 at 13:39 Comment(1)
I have 64 bit setup of ghostscript and imagick but I am facing the same issue, How can I solve it?Vitovitoria
C
1

ImageMagick can't find Ghostscript. The most usual reason for this is that the Ghostscript path is not in the $PATH environment variable, so IM doesn't know where to find it.

Add the Ghostscript installation path (which will vary depending on your OS and the package you use if its a Linux flavour and you us a package) to the $PATH environment variable for the user whic is active when your PHP script runs.

Chak answered 25/12, 2017 at 17:8 Comment(0)
A
1

You don't need to reinstall GhostScript, and, simply adding it to the $PATH will not necessarily solve your problem :/

Here is what you need to do :

  1. On Windows, Ghostscript program is called something like gswin64.exe, so you simply need to rename the file to make it look like gs.exe

  2. And, yeah, make sure the script can be found in the $PATH

Apis answered 19/4, 2021 at 10:54 Comment(0)
R
-1

I have a same issue when i try convert pdf to image.

$imagick = new Imagick();
$imagick->readImage(dirname(__FILE__). '/test.pdf'); 

My solution in WINDOWS. Execute terminal shell of php :)

shell_exec('magick -density 200 C:\laragon\www\cobupemws\public\6258.pdf[0] -quality 100 C:\laragon\www\cobupemws\public\testDemoterminal.jpg');

My solution in LINUX. Execute terminal shell of php :)

shell_exec('convert -density 300 -background white -quality 100  -alpha remove 1.pdf test.jpg');
Rhapsody answered 5/6, 2023 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.