pdf with preview image

9 posts by 4 authors in: Forums > CMS Builder
Last Post: January 20, 2014   (RSS)

By Maurice - January 14, 2014

Hi has anyone done this

upload a pdf and generate a preview image or upload a image.

grts Maurice 

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

Dropmonkey.nl

By aev - January 16, 2014

Hi,

we are also very interested in a feature like this. We have many clients uploading PDFs of brochures and manuals, and it would be great to be able to present a thumbnail/preview from these uploads.

Did some googling and it seems like ImageMagick/Ghostscript can do this, I'm unsure if GD is capable.

Maybe Interactivetools can extend CMSB or create a plugin to do this?

-aev-

By Djulia - January 16, 2014

Hi,

I use this script for my projects :
http://www.veryinteractivepeople.com/?p=521

With a little chance, it can function on your server.

Djulia

By Djulia - January 16, 2014 - edited: January 16, 2014

An example :

if($upload['extension'] == 'pdf') {
    $path_parts = pathinfo($upload['filePath']);
    /*
    [dirname] => /home/www/folder/...
    [basename] => filename.pdf
    [extension] => pdf
    [filename] => filename
    */
   
    $pdf = $upload['filePath'];
    $quality = 90;
    $res = '30x30';
    $exportPath = $path_parts['dirname'].'/'.$record['num'].'_'.$path_parts['filename'].'.jpg';
    exec("'gs' '-dFirstPage=1' '-dLastPage=1' '-dNOPAUSE' '-sDEVICE=jpeg' '-dUseCIEColor' '-dTextAlphaBits=4' '-dGraphicsAlphaBits=4' '-o$exportPath' '-r$res' '-dJPEGQ=$quality' '$pdf'",$output);
}

echo '<img>...';

You must certainly adapt it to your need.

It is also possible to adapt it in a plugin for a use in backend.

Djulia

By aev - January 16, 2014

I think this would work great for an upload field. We can than run your code to produce and present the thumbnails (maybe there should be some kind of cache). But I was more thinking about a wysiwyg field, then the client must know the url to manually insert the thumbnail and then link it to the PDF. For most clients this would be too technical and difficult.

But thanks for your code, it is an interesting starting point, but I hope Dave and his team will implement this into CMSB.

-aev-

By Djulia - January 16, 2014

> (maybe there should be some kind of cache).
Yes, I make some check if the image is generated (for a period of time).
In this case, I use this image.
In the contrary case, I use script.

Thanks!

Djulia

By Maurice - January 17, 2014

All the idea's look great!!

i'm going to look into it next week hope to come with some great idea's my self and with my programmers.

I too wish it would be a standard feature in cmsb

Thnx 

Maurice

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

Dropmonkey.nl

By ross - January 20, 2014

Hi Maurice

At this time we don't have plans for PDF thumbnails officially but I also like the ideas brought up in this thread. Keep us up to date with how you make out!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/