Plugin này chưa được cập nhật với 3 phiên bản mới nhất của WordPress. Nó có thể không được hỗ trợ và bảo trì, và có thể xung đột với các phiên bản WordPress mới nhất.

PDF Thumbnails

Mô tả

This plugin hooks into the media manager and generates a thumbnail everytime a
PDF is uploaded. Generated thumbnail is an image of the first page in the
uploaded document and is named PDFNAME-thumbnail, where PDFNAME is replaced
by uploaded document filename.

Generated thumbnails are equivalent to featured
so that common thumbnail
functions like get_post_thumbnail_id() can be used for PDF attachments. See
Post Thumbnails for information
on how you can use thumbnails efficiently.

Integration with the javascript media API is not yet implemented, therefore, you
may need to reload the page before you can see generated thumbnail after an


It is possible to display a thumbnail linking to an uploaded PDF using the [pdf_thumbnails_link]
shortcode. The following attributes are supported:

Example 1: Display link to PDF with ID = 172 using default thumbnail size

[pdf_thumbnails_link id="172"]

Example 2: Display link to PDF with ID = 172 using thumbnail size (default 150×150)

[pdf_thumbnails_link id="172" size="thumbnail"]

Thanks to mirgcire for providing the first
version of the [pdf_thumbnails_link] shortcode.

Developer API

In most cases it should be sufficient to use built-in thumbnail functions from
the WordPress API (get_post_thumbnail and similar). If you need to modify the
way thumbnails are generated, you can override image generation with
the pdf_thumbnails_generate_image_blob filter.

Example 1: Increase resolution for all generated PDF thumbnails

// $blob is the current image blob (defaults to null, can be used for chaining)
// $filename is the PDF filename
add_action('pdf_thumbnails_generate_image_blob', function ($blob, $filename) {
    $imagick = new Imagick();
    return $imagick->getImageBlob();
}, 10, 2);

It is possible to modify generated thumbnail links using the pdf_thumbnails_link_shortcode
filter. The following attributes are available:

  • $html – Generated HTML code to be displayed
  • $attachmentId – Sanitized ID of the PDF attachment
  • $size – Sanitized thumbnail size
  • $attsShortcode attributes (not sanitized)
  • $content – Shortcode content (not sanitized)

Example 2: Wrap thumbnail link in figure and append caption

add_filter('pdf_thumbnails_link_shortcode', function ($html, $attachmentId, $size, $atts, $content) {
    return "<figure>$html <caption>Click to open image $attachmentId</caption></figure>";
}, 10, 5);


Add generated image to media browser after upload.

Outline of an implementation based on the javascript media API:

// New uploads
wp.Uploader.queue.on('add', function (attachment) {

    if (attachment.subtype !== 'pdf') {

    findThumbnailFor(attachment.ID).then(function (data) {

        // Add attachment thumbnail to browser
        var attachment =
        attachment.fetch().done(function () {
  'library').add(generated attachment)


Filter: ajax_query_attachments_args

Cài đặt

PDF Thumbnails requires ImageMagick with GhostScript support. If you are lucky,
this is already installed on your system, otherwise, installation can be done
with the following steps:

  1. Install ghostscript
  2. Install imagemagick with ghostscript support
  3. Install PHP extension for imagemagick (can use pecl)
  4. Restart web server for changes to take effect

Details may differ based on which operating system you are running, see
Support for
more resources and tips on how this can be done in Windows, Linux and OSX.

Debian / Ubuntu

sudo apt-get install ghostscript php5-imagick
sudo service apache2 restart

Đánh giá

17 Tháng Sáu, 2019 2 replies
As of June 2019, this plug-in does not seem to be functioning on our site. It has not been updated for 3 years. We are using WordPress 5.2.1.
21 Tháng Hai, 2019
thank you so much! i just needed to enable imagik and ask my host to speed up the php libraries' updating process, it already had pdf support.
28 Tháng Sáu, 2018
Works just like it should. Can't believe this functionality isn't in the WP core. Thanks!
3 Tháng Chín, 2016 1 reply
The plugin does just what it says and the author is very helpful. My only suggestion would be to add a short code that would insert a clickable thumbnail into a webpage. Clicking on that would open the PDF in a viewer. For example: [pdf-thumbnail id="1234" size="medium"] ... naturally this functionality would require host support for imagick.
Đọc tất cả 9 đánh giá

Người đóng góp & Lập trình viên

“PDF Thumbnails” là mã nguồn mở. Những người sau đã đóng góp vào plugin này.

Những người đóng góp

Nhật ký thay đổi

This plugin use semantic versioning, i.e. breaking changes
increase the MAJOR version.


  • Support title, target, and download attributes in pdf_thumbnails_link shortcode


  • Support thumbnail links with the pdf_thumbnails_link shortcode
  • Support link customization using the pdf_thumbnails_link_shortcode filter


  • Replaced pdf_thumbnails_before_get_image_blob hook with pdf_thumbnails_generate_image_blob filter


  • Introduced pdf_thumbnails_before_get_image_blob hook