On execution I was getting no image and the following error:
"identify: Postscript delegate failed `..[snip path]../foo.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/668.".
Debugging showed that the shell_exec() to get the page count was returning NULL.
The issue is that ImageMagick's delegates.xml file calls "gs" without any path prefix, so it's expecting gs to be on the path. Apache is configured to present an empty path to PHP (at least on my system) so although ImageMagick executes, "gs" fails as it's not on the path.
The solution that worked for me was to use putenv() to add /usr/local/bin to the path right before the shell_exec().
I am using a variable called pdf_to_imagefield_gs_path that works similar to the imagemagick_convert variable so this can be easily modified. This variable should contain the full path to gs, and defaults to /usr/local/bin/gs
As this was a pain to debug I added some error and dependency checking to the functions that will hopefully help other people trying to get this working.
I also switched out the command to pull the page count with a different version from http://stackoverflow.com/questions/4826485/ghostscript-pdf-total-pages that appears to fetch the pagecount metadata which should be much faster than rendering all pages (the page count code supplied was still failing for me).
Hope this is helpful!
| Comment | File | Size | Author |
|---|---|---|---|
| pdf_to_imagefield.patch | 2.61 KB | garethsprice |
Comments
Comment #1
dman commentedWow what a pain that must have been to track down.
I remember having to dig way too deep to get gs dependencies going.
I'm not sure that putenv is the *best* solution, but I can't suggest another if - as you say - the trouble really was in delegates.xml
I'd be unhappy with a server that didn't have *anything* in its path, so I guess that's why it's not a problem I'd encountered.
I have tried the alternate (apparently quicker) way to count pages, but in testing PDFs that were built from several different engines I found it unreliable. Actually counting the pages turned out to be the basic way to do it. I was not able to figure out why it sometimes failed as it means digging into the pdf binary itself - which felt mad.
Anyway - SOME PDFs did not have that metadata in the place where it was looking.
I'll see if this version causes problems on some test cases I guess.
Comment #2
dman commentedA fixup related to this issue is in the current 3.x dev.
Peculiarly, what was needed was this:
Which looks ridiculous, but demonstrably solved a problem finding gs on Acquia dev desktop OSX today.