Openning a PDF file

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Excale
Posts: 13
Joined: 2010-12-05T23:39:53-07:00
Authentication code: 8675308

Openning a PDF file

Post by Excale »

Hi,

I am trying to use Imagemagick with Imagick on PHP. In general Imagick is working fine.
My hoster also installed Ghostscript, but I cannot find the word "ghostscript" in phpinfo.

When I want to open a pdf file, I have this error (I tried several pdf files):

Code: Select all

Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `/tmp/magick-XXgzb2Yt': @ error/pdf.c/ReadPDFImage/645' in /home/httpd/h/a/d/hadrien/shci.franceserv.com/pdf/test.php:2 Stack trace: #0 /home/httpd/h/a/d/hadrien/shci.franceserv.com/pdf/test.php(2): Imagick->__construct('test.pdf') #1 {main} thrown in /home/httpd/h/a/d/hadrien/shci.franceserv.com/pdf/test.php on line 2
with "$im = new imagick( 'test.pdf' );"

Or:

Code: Select all

Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `test.pdf': @ error/pdf.c/ReadPDFImage/645' in /home/httpd/h/a/d/hadrien/shci.franceserv.com/PDF/test.php:3 Stack trace: #0 /home/httpd/h/a/d/hadrien/shci.franceserv.com/PDF/test.php(3): Imagick->__construct('test.pdf[0]') #1 {main} thrown in /home/httpd/h/a/d/hadrien/shci.franceserv.com/PDF/test.php on line 3
with "$im = new imagick( 'test.pdf[0]' );"


Thank you for your help!
Last edited by Excale on 2010-12-17T10:53:10-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Openning a PDF file

Post by fmw42 »

It does not look like it is installed correctly or where IM knows about it (or perhaps PHP does not know about it). Was IM recompiled after Ghostscript? If not try reinstalling IM. Also look at the IM config.log file and see if it shows any error message about Ghostscript (GS) installation with IM. Furthermore, you need to install the GS fonts and tell IM where they are located. see http://www.imagemagick.org/script/advan ... lation.php

For example my ./configure file shows:

./configure CPPFLAGS='-I/opt/local/include' LDFLAGS='-L/opt/local/lib' \
--enable-delegate-build --enable-shared --disable-static \
--with-modules --with-quantum-depth=16 --enable-hdri --with-gslib --without-wmf \
--disable-silent-rules --disable-dependency-tracking \
--with-gs-font-dir=/opt/local/share/ghostscript/fonts/ --with-lqr


Once IM is installed you can see all the delegate libraries for jpg, png, tiff and gs by

convert -list configure

and looking at the line starting with DELEGATES

DELEGATES bzlib fftw fontconfig freetype gs jpeg jng jp2 lcms lqr mpeg openexr png rsvg tiff x11 xml zlib


But delegates generally need to be installed before installing IM.
Excale
Posts: 13
Joined: 2010-12-05T23:39:53-07:00
Authentication code: 8675308

Re: Openning a PDF file

Post by Excale »

Thank you for your quick anwser, i'll see it with my hoster :D .
Excale
Posts: 13
Joined: 2010-12-05T23:39:53-07:00
Authentication code: 8675308

Re: Openning a PDF file

Post by Excale »

Hi again, I still have the same problem.
My hoster turned to IM 6.6.6.5.

This is the line to compile:

Code: Select all

    ./configure --prefix=/usr --with-gslib --with-gs-font-dir=/usr/share/fonts/Type1/ --libdir=/usr/lib64 --mandir=/usr/man --program-prefix= --with-x --with-frozenpaths=no --without-modules --disable-openmp --enable-static=no --enable-shared --with-perl --build=x86_64-slackware-linux build_alias=x86_64-slackware-linux
We get this (this time there is "gs" in the list):

Code: Select all

    #convert -list configure | grep ^DELEGATES
    DELEGATES     bzlib djvu fftw freetype gs jpeg jng jp2 lcms openexr png tiff wmf zlib
But there is still the same error when I try to use Imagick with PHP:

Code: Select all

Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `/tmp/magick-XXZ5w4Jl': @ error/pdf.c/ReadPDFImage/645' in /home/httpd/h/a/d/hadrien/shci.franceserv.com/pdf/test.php:2 Stack trace: #0 /home/httpd/h/a/d/hadrien/shci.franceserv.com/pdf/test.php(2): Imagick->__construct('test.pdf') #1 {main} thrown in /home/httpd/h/a/d/hadrien/shci.franceserv.com/pdf/test.php on line 2
In config.log we get:

Code: Select all

configure:27162: checking for Ghostscript
configure:27164: result:
configure:27169: checking ghostscript/iapi.h usability
configure:27169: gcc -std=gnu99 -std=gnu99 -c   -g -O2 -Wall -pthread -I/usr/include/freetype2  conftest.c >&5
configure:27169: $? = 0
configure:27169: result: yes
configure:27169: checking ghostscript/iapi.h presence
configure:27169: gcc -E -I/usr/include/freetype2  conftest.c
configure:27169: $? = 0
configure:27169: result: yes
configure:27169: checking for ghostscript/iapi.h
configure:27169: result: yes
configure:27177: checking ghostscript/ierrors.h usability
configure:27177: gcc -std=gnu99 -std=gnu99 -c   -g -O2 -Wall -pthread -I/usr/include/freetype2  conftest.c >&5
configure:27177: $? = 0
configure:27177: result: yes
configure:27177: checking ghostscript/ierrors.h presence
configure:27177: gcc -E -I/usr/include/freetype2  conftest.c
configure:27177: $? = 0
configure:27177: result: yes
configure:27177: checking for ghostscript/ierrors.h
configure:27177: result: yes
configure:27185: checking for gsapi_new_instance in Ghostscript framework
configure:27210: gcc -std=gnu99 -std=gnu99 -o conftest   -g -O2 -Wall -pthread -I/usr/include/freetype2   conftest.c -framework Ghostscript  -lfreetype -lfftw3 -ldjvulibre -lz -lbz2 -lrt -lm -ldl   -lpthread -lfreetype -lz >&5
gcc: Ghostscript: No such file or directory
I think this line may be interesting:

Code: Select all

configure:27210: gcc -std=gnu99 -std=gnu99 -o conftest   -g -O2 -Wall -pthread -I/usr/include/freetype2   conftest.c -framework Ghostscript  -lfreetype -lfftw3 -ldjvulibre -lz -lbz2 -lrt -lm -ldl   -lpthread -lfreetype -lz >&5
gcc: Ghostscript: No such file or directory
Thank you for your help!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Openning a PDF file

Post by fmw42 »

Perhaps Imagick needs to know about GS and not just ImageMagick. I know little about configuring Imagick.

Why don't you try using PHP with the exec command as it makes calls directly via the command line style of ImageMagick and see if that even works, before trying to use it in Imagick. Or just use a terminal and try your command in command line mode.
Excale
Posts: 13
Joined: 2010-12-05T23:39:53-07:00
Authentication code: 8675308

Re: Openning a PDF file

Post by Excale »

I get the same error:

Code: Select all

#wget http://ftp.free.fr/pub/assistance/reclamation-connexion.pdf
#mv reclamation-connexion.pdf test.pdf
#convert test.pdf test.jpeg
convert: Postscript delegate failed `test.pdf':  @ error/pdf.c/ReadPDFImage/645.
convert: missing an image filename `test.jpeg' @ error/convert.c/ConvertImageCommand/2949.
I hope the "#convert test.pdf test.jpeg" ligne is correct.

Thank you!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Openning a PDF file

Post by fmw42 »

If # is not your terminal prompt, then remove it.

convert test.pdf test.jpeg

Have you tried any other pdf file?

You might try adding -debug to your command and report to the IM developers.

see http://www.imagemagick.org/Usage/basics/#controls

Do your directories have read and write permissions?
Excale
Posts: 13
Joined: 2010-12-05T23:39:53-07:00
Authentication code: 8675308

Re: Openning a PDF file

Post by Excale »

I have news, but I don't know if it is good or bad ones...

It is a long story, but just forget about the #, it was not there in real.
An other pdf file also bug.
And the chmod is 777.

------------------------

I installed ImageMagick et GhostScript on a Debian server (it is a personal server) and "convert" is working, but on the real server (Slackware), still the same problem.

debug gives:

Slackware server were it does not work:

Code: Select all

#convert -debug reclamation-connexion.pdf reclamation-connexion.jpeg
convert: unrecognized event type `reclamation-connexion.pdf' @ error/convert.c/ConvertImageCommand/1116.
Debian server (working but gives an error):

Code: Select all

#convert -debug reclamation-connexion.pdf reclamation-connexion.jpeg
convert: unrecognized event type `reclamation-connexion.pdf'.
verbose gives :

Slackware server were it does not work:

Code: Select all

#convert -verbose reclamation-connexion.pdf reclamation-connexion.jpeg
"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"  "-sOutputFile=/tmp/magick-XX9S7dqA" "-f/tmp/magick-XXSiIJQ2" "-f/tmp/magick-XX17ykhv"
convert: Postscript delegate failed `reclamation-connexion.pdf':  @ error/pdf.c/ReadPDFImage/645.
convert: missing an image filename `reclamation-connexion.jpeg' @ error/convert.c/ConvertImageCommand/2949.
Debian server (working):

Code: Select all

#convert -verbose reclamation-connexion.pdf reclamation-connexion.jpeg
"gs" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"  "-sOutputFile=/tmp/magick-XXZzKpzr" "-f/tmp/magick-XXK6wtJy" "-f/tmp/magick-XXREqDTF"
/tmp/magick-XXZzKpzr PNM 595x842 595x842+0+0 DirectClass 8-bit 1.43341mb 0.010u 0:02
reclamation-connexion.pdf PDF 595x842 595x842+0+0 DirectClass 16-bit 1.43341mb
reclamation-connexion.pdf=>reclamation-connexion.jpeg PDF 595x842 595x842+0+0 DirectClass 16-bit 28.4043kb
Thank you!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Openning a PDF file

Post by fmw42 »

Sorry I know little about linux or servers (I am on a Mac OSX). Perhaps Anthony will have some suggestions.
Excale
Posts: 13
Joined: 2010-12-05T23:39:53-07:00
Authentication code: 8675308

Re: Openning a PDF file

Post by Excale »

I'm back. :D

It seems that Ghostscript just can't work on Slackware. But my hoster has just turned to Debian, wich has a Ghostscript package.

Now it workds fine in command line :D .
But with PHP, I still have an error:
Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `/tmp/magick-XX5HPypc': No such file or directory' in /home/httpd/h/a/d/hadrien/shci.franceserv.com/pdf/test.php:2 Stack trace: #0 /home/httpd/h/a/d/hadrien/shci.franceserv.com/pdf/test.php(2): Imagick->__construct('test.pdf') #1 {main} thrown in /home/httpd/h/a/d/hadrien/shci.franceserv.com/pdf/test.php on line 2

or

Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `test.pdf': No such file or directory' in /home/httpd/h/a/d/hadrien/shci.franceserv.com/pdf/test2.php:3 Stack trace: #0 /home/httpd/h/a/d/hadrien/shci.franceserv.com/pdf/test2.php(3): Imagick->__construct('test.pdf[0]') #1 {main} thrown in /home/httpd/h/a/d/hadrien/shci.franceserv.com/pdf/test2.php on line 3

Maybe I need to ask about it on the Ghostscript forum.

Thanks!
Post Reply