NextGen Gallery PDF Support for this Wordpress Plugin

Da My-Lab.

NextGen Gallery is a very great plugin for Wordpress. Let's add to it another capability: the ability do build pdf thumbnail. Files involved are:


where you'll have to replace inside function create_thumbnail, that call to


to this more sophisticated call. It actually forces thumbnail to be saved in jpeg format, despite it ends with a .pdf; and select first page of a pdf, if it has multiple pages:

                       // save the new thumbnail
                       // MARK
                       $path_info = pathinfo($image->thumbPath);
                       if ($path_info['extension'] == "pdf")
                               @$thumb->save($image->thumbPath.'.jpg', $ngg->options['thumbquality']);
                               if (is_file($image->thumbPath.'.jpg'))
                               elseif (is_file($image->thumbPath.'-0.jpg'))
                               $thumb->save($image->thumbPath, $ngg->options['thumbquality']);

of course you'll have to enable pdf uploads. This is done by replacing:

$ext = array('jpeg', 'jpg', 'png', 'gif');


$ext = array('jpeg', 'jpg', 'png', 'gif','pdf');

everytime it occours inside functions.php file.

Next, last trick: leave out


check, in functions.php; so that:

if ( !in_array($filepart['extension'], $ext)) || !@getimagesize($temp_file) ){


if ( !in_array($filepart['extension'], $ext)){ // || !@getimagesize($temp_file) ){


if (!@getimagesize($gallerypath . '/' . $picture) ) {
                               @unlink($gallerypath . '/' . $picture);          


/* if (!@getimagesize($gallerypath . '/' . $picture) ) {
                               @unlink($gallerypath . '/' . $picture);          
                       } */

(getimagesize does not work with pdf file, hence we have to skip this step, or it should be performed in another way, such as through ImageMagick). Of course you have to use imagemagick as thumnailer, not gd embedded php library (this might pose some problem if you're on a shared hosting, otherwise, apt-get it and configure it trough NextGen Gallery -> Options -> Select graphic library: -> ImageMagick). Last but not least, don't use a picture highlighter, such as shadowbox, or jquery stuff like that: they won't work with pdf files, and you will end up showing nothing but the little preview out there.

Thumbnail cropping and resizing does not work with pdf, but believe me, it will be nice and clean in spite of all.

For those who love fancy boxes

If you still want to enjoy fancy boxes on the rest of your site, here is the howto. Just walk into your own theme folder (such as wp-content/themes/eNews) and create a folder named


Inside it copy the file:




And in this new copy, delete this code, where you find it:

<?php echo $image->thumbcode ?>

Next, when you'll want to show a pdf gallery, just remember to call nextgen this way:

[nggallery id=1 template=pdf]