PDFPreview User error: ImageMagick error 1: convert: no images defined

On my local development environment (a macbook pro running El Capitan), whenever I installed PDFPreview and tried to view a page that utilized it, I would get an error like:

User error: ImageMagick error 1: convert: no images defined `/path/to/pdfpreview/folder/filetowrite.jpg' @ error/convert.c/ConvertImageCommand/3241. in trigger_error() (line 519 of /path/to/drupal/sites/all/modules/imagemagick/imagemagick.module). =>

Searching the pdfpreview issues only turned up a page where people seemed to think it was due to spaces in the filename, which was not my experience. I faced this error whether there were spaces in the filename or not. I had faced a similar issue with PDF to thumbnail, but I thought that since I had gotten the issue resolved it must be something else, but it turned out to be the same issue. Ghostscript, which is required for Imagemagick to be able to convert PDF files, was not in Apache's path. I don't remember exactly how I fixed PDF to Image, but I'm very confused why that fix didn't carry over.

To check your own Apache path from Drupal go to /admin/reports/status/php, scroll down to Apache Environment, and look for PATH. If you've installed imagemagick via homebrew as I have your gs executable will be symlinked into /usr/local/bin. If you are not on El Capitan you have all kinds of options, mostly revolving around changing your global PATH environmental variable or symlinking gs into a directory that IS in Apache's path. Unfortunately I'm running El Capitan which has SIP (System Integrity Protection or something like that), also known as rootless. Basically this means that even as a root user I can't modify some system directories. In this case the two locations I desperately wanted to adjust were either /System/Library/LaunchDaemons/org.apache.httpd.plist (this guy claims he made the change under El Capitan to this file, but it seems like he must have disabled SIP first) or /usr/bin

I seriously considered disabling SIP myself, and I still may, but I really wanted to find a way around this without requiring me to restart into recovery mode. My final solution was just to do it in PHP (credit one place where I found the info). I added this line to the top of my settings.php and now the PDF Preview magically works:

$path = getenv('PATH'); putenv( "PATH=$path:/usr/local/bin" );

I hope this helps someone grind their teeth a lot less than I did today!

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.