PDF and PS thumbnails with ImageMagick + ImageCache (WITHOUT iPaper)
I was just trying to figure out how to get a thumbnail preview of PDF and PS files. Apparently there's no support for that, so I tweaked some of the exisiting code for a quick solution. This is pretty straight forward, how I find, though it is still dirty, 'cause it changes modules of other people. But perhaps someone likes to use it as a workaround until some similar solution makes it into the original module code.
- What we have is:
- Drupal 6.11
- Content Construction Kit
- FileField
- ImageField
- ImageCache 6.x-2.0-beta9 < That's where we will do our changes.
- ImageAPI
- ImageCache Actions
Ok, let's patch imagecache.module:
$dst = imagecache_create_path($preset['presetname'], $path);
+ if ($gs = in_array(strtolower(substr($dst, strrpos($dst, "."))), array(".ps", ".pdf"))) $dst .= ".png";- if (!getimagesize($src)) {
+ if (!getimagesize($src) && !$gs) {That's it with the in-module code.
Now add a new imagecache preset through your drupal site's admin menu and, as the only action to take, choose custom action and enter this:
_imageapi_imagemagick_convert($image->source."[0]", $image->source.=".png", array(0 => "-thumbnail 100"));
return $image;You should be able to add more converting actions to - for example - put a frame and the PDF-Logo or something. The calculated preset is available in Views, just where you want it.
Don't forget to change your ImageAPI to Imagemagick and have GhostScript installed.
Sure.. this is not perfect, but it's a quick solution that - hopefully - will not require many changes once this kind of functionality becomes part of ImageCache in a more professional way.
So, if someone can make use of this.. just let me know.

_
Thanks for writing this up! You should really consider submitting this as a patch to the imagecache module.
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
This is fantastic! Just what
This is fantastic! Just what I needed - thanks for posting, frankiedesign!
Just one question - the first time I click on the new pdf thumbnails I get the following warning:
warning: extract() [function.extract]: First argument should be an array in ...\sites\all\modules\imagecache_actions\imagecache_customactions.module on line 121.
Could anyone tell me what this means, how to fix it, or if it's serious?
Thanks again
is there a way to make it
is there a way to make it work with ImageGD instead of ImageMagick?
thank you!
Doesn't quite work...
Hi,
Thanks for this -- it would be exactly what I need if I could get it to work! I've installed all the necessary binaries and modules, added a file field to the relevant content type with the display set to my imagecache preset, but the conversion isn't happening. The resultant html contains the correct link to the pdf file but the img src is set to the pdf filename in the imagecache directory instead of an image file. No image is being created. Perhaps I've missed a step somewhere?
Update: I've found a solution that (almost) works: http://drupal.org/node/366373
fantastic!
This looks fantastic and I plan to have a bit of a play with this tomorrow for a future project...
One question comes to mind now - I would really like to take this a step forward and create images of all the pages in the PDF and attach them to the node. Have you already tried to do this??
Cheers!!
Displaying the file link as well as the image
Hi,
Your instructions were perfect and I have my site generating a png file from the pdf that I upload via filefield.
But...how do I go about getting the page to display both the image and the original link to the file. There is no option in the display fields to do this :-(
Thanks
Rich
multiple page
Few quick question tho. Does it work with multiple pages PDF? PDF with dynamic content and java script such (as a pdf form)?
Thanks
subscribe
subscribe
subscribe
subscribe
Generate PDF thumbnails with ImageMagick while GD is selected
See http://drupal.org/node/578804
If you're interested I can post the code.