Title: PDF Thumbnails
Author: stianlik
Published: <strong>2014 年 4 月 7 日</strong>
Last modified: 2016 年 10 月 24 日

---

搜尋外掛

這個外掛**並未在最新的 3 個 WordPress 主要版本上進行測試**。開發者可能不再對這個
外掛進行維護或提供技術支援，並可能會與更新版本的 WordPress 產生使用上的相容性問題。

![](https://s.w.org/plugins/geopattern-icon/pdf-thumbnails.svg)

# PDF Thumbnails

 由 [stianlik](https://profiles.wordpress.org/stianlik/) 開發

[下載](https://downloads.wordpress.org/plugin/pdf-thumbnails.2.2.0.zip)

 * [詳細資料](https://tw.wordpress.org/plugins/pdf-thumbnails/#description)
 * [使用者評論](https://tw.wordpress.org/plugins/pdf-thumbnails/#reviews)
 *  [安裝方式](https://tw.wordpress.org/plugins/pdf-thumbnails/#installation)
 * [開發資訊](https://tw.wordpress.org/plugins/pdf-thumbnails/#developers)

 [技術支援](https://wordpress.org/support/plugin/pdf-thumbnails/)

## 外掛說明

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
 images
 so that common thumbnail
 functions like `get_post_thumbnail_id()` can be used for PDF attachments. See [Post Thumbnails](https://codex.wordpress.org/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 upload.

#### Shortcodes

It is possible to display a thumbnail linking to an uploaded PDF using the `[pdf_thumbnails_link]`

shortcode. The following attributes are supported:

 * `id` – Attachment ID (required)
 * `size` – [Thumbnail size](https://codex.wordpress.org/Post_Thumbnails#Thumbnail_Sizes)(
   optional)
 * `title` – [Anchor title attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#attr-title)(
   optional)
 * `target` – [Anchor target attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target)(
   optional)
 * `download` – [Anchor download attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download)(
   optional)

Example 1: Display link to PDF with ID = 172 using [default thumbnail size](https://codex.wordpress.org/Post_Thumbnails#Thumbnail_Sizes)

    ```
    [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](https://wordpress.org/support/profile/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();
        $imagick->setResolution(200,200);
        $imagick->readImage($filename);
        $imagick->setIteratorIndex(0);
        $imagick->setImageFormat('jpg');
        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
 * `$atts` – [Shortcode attributes (not sanitized)](https://codex.wordpress.org/Shortcode_API#Handling_Attributes)
 * `$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);
    ```

### TODO

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') {
            return;
        }

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

            // Add attachment thumbnail to browser
            var attachment = wp.media.model.Attachment.get(id)
            attachment.fetch().done(function () {
                wp.media.editor.open().state().get('library').add(generated attachment)
            });

        });
    });
    ```

Filter: ajax_query_attachments_args

## 安裝方式

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](https://wordpress.org/support/topic/nothing-but-error-messages)
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
    ```

## 使用者評論

![](https://secure.gravatar.com/avatar/f5342bf6cc07ae70cf790ea7517ce2825a0b6b56ed567a0ce91a13d63c3be7bc?
s=60&d=retro&r=g)

### 󠀁[No longer supported](https://wordpress.org/support/topic/no-longer-supported-45/)󠁿

 [joyrowe](https://profiles.wordpress.org/joyrowe/) 2019 年 6 月 17 日 2 則留言

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.

![](https://secure.gravatar.com/avatar/23a4e26b2f04dd62524c56c4f5de118aee693325a97297555cd0888cec1977fa?
s=60&d=retro&r=g)

### 󠀁[great!](https://wordpress.org/support/topic/great-9287/)󠁿

 [formgiver](https://profiles.wordpress.org/formgiver/) 2019 年 2 月 21 日

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.

![](https://secure.gravatar.com/avatar/0356e26926a595453167b3f96768405e79a4f37ca02bde5828c00f1d5bca268c?
s=60&d=retro&r=g)

### 󠀁[Excellent](https://wordpress.org/support/topic/excellent-6432/)󠁿

 [jonsisk](https://profiles.wordpress.org/jonsisk/) 2018 年 6 月 28 日

Works just like it should. Can’t believe this functionality isn’t in the WP core.
Thanks!

![](https://secure.gravatar.com/avatar/2029c4cd99d1943ecff96e02cd0e23b921ad3b9a6fbba10bb51caad134eb91b3?
s=60&d=retro&r=g)

### 󠀁[Nice Job](https://wordpress.org/support/topic/nice-job-124/)󠁿

 [mirgcire](https://profiles.wordpress.org/mirgcire/) 2016 年 9 月 3 日 1 則留言

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.

![](https://secure.gravatar.com/avatar/8ed8207c09810a665f92c360c240630548faa1a599ffae27cefa7e6b53370153?
s=60&d=retro&r=g)

### 󠀁[Works as expected](https://wordpress.org/support/topic/works-as-expected-170/)󠁿

 [winnewoerp](https://profiles.wordpress.org/joschi81/) 2016 年 9 月 3 日

This plugin does what it’s supposed to do. No problems.

 [ 閱讀全部 9 則使用者評論 ](https://wordpress.org/support/plugin/pdf-thumbnails/reviews/)

## 參與者及開發者

以下人員參與了開源軟體〈PDF Thumbnails〉的開發相關工作。

參與者

 *   [ stianlik ](https://profiles.wordpress.org/stianlik/)
 *   [ mirgcire ](https://profiles.wordpress.org/mirgcire/)

[將〈PDF Thumbnails〉外掛本地化為台灣繁體中文版](https://translate.wordpress.org/projects/wp-plugins/pdf-thumbnails)

### 對開發相關資訊感興趣？

任何人均可[瀏覽程式碼](https://plugins.trac.wordpress.org/browser/pdf-thumbnails/)、
查看 [SVN 存放庫](https://plugins.svn.wordpress.org/pdf-thumbnails/)，或透過 [RSS](https://plugins.trac.wordpress.org/log/pdf-thumbnails/?limit=100&mode=stop_on_copy&format=rss)
訂閱[開發記錄](https://plugins.trac.wordpress.org/log/pdf-thumbnails/)。

## 變更記錄

This plugin use [semantic versioning](http://semver.org/), i.e. breaking changes

increase the MAJOR version.

#### 2.2.0

 * Support title, target, and download attributes in `pdf_thumbnails_link` shortcode

#### 2.1.0

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

#### 2.0.0

 * Replaced `pdf_thumbnails_before_get_image_blob` hook with `pdf_thumbnails_generate_image_blob`
   filter

#### 1.0.2

 * Introduced `pdf_thumbnails_before_get_image_blob` hook

## 中繼資料

 *  版本 **2.2.0**
 *  最後更新 **9 年前**
 *  啟用安裝數 **1,000+**
 *  已測試相容的 WordPress 版本 **4.6.30**
 *  語言
 * [English (US)](https://wordpress.org/plugins/pdf-thumbnails/)
 * 標籤
 * [generator](https://tw.wordpress.org/plugins/tags/generator/)[pdf](https://tw.wordpress.org/plugins/tags/pdf/)
   [thumbnail](https://tw.wordpress.org/plugins/tags/thumbnail/)
 *  [進階檢視](https://tw.wordpress.org/plugins/pdf-thumbnails/advanced/)

## 評分

 4.6 星，滿分為 5 星

 *  [  8 個 5 星使用者評論     ](https://wordpress.org/support/plugin/pdf-thumbnails/reviews/?filter=5)
 *  [  0 個 4 星使用者評論     ](https://wordpress.org/support/plugin/pdf-thumbnails/reviews/?filter=4)
 *  [  0 個 3 星使用者評論     ](https://wordpress.org/support/plugin/pdf-thumbnails/reviews/?filter=3)
 *  [  0 個 2 星使用者評論     ](https://wordpress.org/support/plugin/pdf-thumbnails/reviews/?filter=2)
 *  [  1 個 1 星使用者評論     ](https://wordpress.org/support/plugin/pdf-thumbnails/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/pdf-thumbnails/reviews/#new-post)

[查看全部使用者評論](https://wordpress.org/support/plugin/pdf-thumbnails/reviews/)

## 參與者

 *   [ stianlik ](https://profiles.wordpress.org/stianlik/)
 *   [ mirgcire ](https://profiles.wordpress.org/mirgcire/)

## 技術支援

使用者可在技術支援論壇提出意見反應或使用問題。

 [檢視技術支援論壇](https://wordpress.org/support/plugin/pdf-thumbnails/)