PDF thumbnail generation in WordPress – You may not need a plugin!

I was working on a WordPress website in which I needed to create thumbnails from PDF file uploads. As I  work with WordPress less frequently these day I was not aware of an amazing update and fact about PDF thumbnail generation in WordPress.

Thanks to the WordPress update page, every time you upload a PDF file through media library, different thumbnail sizes are generated for the same.  The thumbnail information could be retrieved using attachment functions.

For example, the function wp_get_attachment_metadata($attachment_id) would give an array of all sizes, something like this:

[sizes] => Array
           (
               [thumbnail] => Array
                   (
                       [file] => press_image-150x150.jpg
                       [width] => 150
                       [height] => 150
                       [mime-type] => image/jpeg
                   )
               [medium] => Array
                   (
                       [file] => press_image-4-300x194.jpg
                       [width] => 300
                       [height] => 194
                       [mime-type] => image/jpeg
                   )
               [large] => Array
                   (
                       [file] => press_image-1024x665.jpg
                       [width] => 1024
                       [height] => 665
                       [mime-type] => image/jpeg
                   )
               [post-thumbnail] => Array
                   (
                       [file] => press_image-624x405.jpg
                       [width] => 624
                       [height] => 405
                       [mime-type] => image/jpeg
                   )
           )
       [image_meta] => Array
           (
               [aperture] => 5
               [credit] => 
               [camera] => Canon EOS-1Ds Mark III
                => 
               [created_timestamp] => 1323190643
               [copyright] => 
               [focal_length] => 35
               [iso] => 800
               [shutter_speed] => 0.016666666666667
               [title] => 
           )

And wp_get_attachment_thumb_url() will get the full url of the thumbnail.

In order to work PDF thumbnail generation in WordPress you need to enable

So if you are looking for PDF thumbnails generation plugin you may need to look into the inbuilt functions first.

You may need to look at this post for more detailed post about PDF thumbnail generation and regeneration in WordPress.

Leave a Reply

Your email address will not be published. Required fields are marked *