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";
This is for telling the ImageAPI to produce a PNG output as a thumb, not a small PDF.
- if (!getimagesize($src)) {
+ if (!getimagesize($src) && !$gs) {
This is for making imagecache continue, even without a bitmap style image.
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;
The 100 can be replaced by other sizes or even by fixed values like 120x80, the [0] stands for the first page of the document. Just have a look at man convert.
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.
Comments
_
Thanks for writing this up! You should really consider submitting this as a patch to the imagecache module.
Patch available
Just attached a patch mentioning this post at #366373: PDF support ( i.e. convert PDF to JPG support)
--
develCuy
Hiring the next generation front-end devs, contact Dilygent
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.
I am interested!
I am interested!
Generate PDF thumbnails with ImageMagick while GD is selected
Have a look at:
http://drupal.org/node/641372
subscribe
subscribe
subscribing.
subscribing.
Subscribe
Subscribe
I'm curious if anyone has
I'm curious if anyone has made an attempt to get this working under D7. It looks like things have been muddled with transition of imageapi / imagecache into core, and the complete disappearance of the function imagecache_create_path().
I'm curious too
I'm also working in D7 and need a streamlined way for non-technical front-end users to add PDF newsletters with linked thumbnails. Seems like this must be out there for D7 already, I'm just not finding it.
I was finally able to do
I was finally able to do this, although it involved adding lots of custom code to theme templates that invoke functions from the imagemagick module, and generate thumbnails of PDFs on demand. The only way I can imagine getting this better integrated into the D7 media module is to push this code into a custom module that provides additional style(s) to the media module based on MIME type.
Here is example code from API.txt provided with the media module. Basically, a custom module would invoke the PDF/EPS thumbnail generation when the relevant MIME type is encountered.
I'd love to see something
I'd love to see something like this for D7 too...