{"id":28669,"date":"2014-04-07T06:06:50","date_gmt":"2014-04-07T06:06:50","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/pdf-thumbnails\/"},"modified":"2016-10-24T20:49:44","modified_gmt":"2016-10-24T20:49:44","slug":"pdf-thumbnails","status":"publish","type":"plugin","link":"https:\/\/srd.wordpress.org\/plugins\/pdf-thumbnails\/","author":13752624,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"2.2.0","stable_tag":"2.2.0","tested":"4.6.30","requires":"","requires_php":"","requires_plugins":"","header_name":"PDF Thumbnails","header_author":"Stian Liknes","header_description":"","assets_banners_color":"","last_updated":"2016-10-24 20:49:44","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"","header_author_uri":"","rating":4.6,"author_block_rating":0,"active_installs":1000,"downloads":34492,"num_ratings":9,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","changelog"],"tags":[],"upgrade_notice":[],"ratings":{"1":"1","2":0,"3":0,"4":0,"5":"8"},"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":["0.0.2","0.0.3","0.0.4","0.0.5","0.0.6","1.0.0","1.0.1","1.0.2","2.0.0","2.1.0","2.2.0"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[2209,1764,1326],"plugin_category":[50],"plugin_contributors":[82102,82101],"plugin_business_model":[],"class_list":["post-28669","plugin","type-plugin","status-publish","hentry","plugin_tags-generator","plugin_tags-pdf","plugin_tags-thumbnail","plugin_category-media","plugin_contributors-mirgcire","plugin_contributors-stianlik","plugin_committers-stianlik"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/pdf-thumbnails.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>This plugin hooks into the media manager and generates a thumbnail everytime a\nPDF is uploaded. Generated thumbnail is an image of the first page in the\nuploaded document and is named <code>PDFNAME-thumbnail<\/code>, where <code>PDFNAME<\/code> is replaced\nby uploaded document filename.<\/p>\n\n<p>Generated thumbnails are equivalent to <a href=\"https:\/\/codex.wordpress.org\/Post_Thumbnails\">featured\nimages<\/a> so that common thumbnail\nfunctions like <code>get_post_thumbnail_id()<\/code> can be used for PDF attachments. See\n<a href=\"https:\/\/codex.wordpress.org\/Post_Thumbnails\">Post Thumbnails<\/a> for information\non how you can use thumbnails efficiently.<\/p>\n\n<p>Integration with the javascript media API is not yet implemented, therefore, you\nmay need to reload the page before you can see generated thumbnail after an\nupload.<\/p>\n\n<h4>Shortcodes<\/h4>\n\n<p>It is possible to display a thumbnail linking to an uploaded PDF using the <code>[pdf_thumbnails_link]<\/code>\nshortcode. The following attributes are supported:<\/p>\n\n<ul>\n<li><code>id<\/code> - Attachment ID (required)<\/li>\n<li><code>size<\/code> - <a href=\"https:\/\/codex.wordpress.org\/Post_Thumbnails#Thumbnail_Sizes\">Thumbnail size<\/a> (optional)<\/li>\n<li><code>title<\/code> - <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Global_attributes#attr-title\">Anchor title attribute<\/a> (optional)<\/li>\n<li><code>target<\/code> - <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/a#attr-target\">Anchor target attribute<\/a> (optional)<\/li>\n<li><code>download<\/code> - <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/a#attr-download\">Anchor download attribute<\/a> (optional)<\/li>\n<\/ul>\n\n<p>Example 1: Display link to PDF with ID = 172 using <a href=\"https:\/\/codex.wordpress.org\/Post_Thumbnails#Thumbnail_Sizes\">default thumbnail size<\/a><\/p>\n\n<pre><code>[pdf_thumbnails_link id=\"172\"]\n<\/code><\/pre>\n\n<p>Example 2: Display link to PDF with ID = 172 using thumbnail size (default 150x150)<\/p>\n\n<pre><code>[pdf_thumbnails_link id=\"172\" size=\"thumbnail\"]\n<\/code><\/pre>\n\n<p>Thanks to <a href=\"https:\/\/wordpress.org\/support\/profile\/mirgcire\">mirgcire<\/a> for providing the first\nversion of the <code>[pdf_thumbnails_link]<\/code> shortcode.<\/p>\n\n<h4>Developer API<\/h4>\n\n<p>In most cases it should be sufficient to use built-in thumbnail functions from\nthe WordPress API (<code>get_post_thumbnail<\/code> and similar). If you need to modify the\nway thumbnails are generated, you can override image generation with\nthe <code>pdf_thumbnails_generate_image_blob<\/code> filter.<\/p>\n\n<p>Example 1: Increase resolution for all generated PDF thumbnails<\/p>\n\n<pre><code>\/\/ $blob is the current image blob (defaults to null, can be used for chaining)\n\/\/ $filename is the PDF filename\nadd_action('pdf_thumbnails_generate_image_blob', function ($blob, $filename) {\n    $imagick = new Imagick();\n    $imagick-&gt;setResolution(200,200);\n    $imagick-&gt;readImage($filename);\n    $imagick-&gt;setIteratorIndex(0);\n    $imagick-&gt;setImageFormat('jpg');\n    return $imagick-&gt;getImageBlob();\n}, 10, 2);\n<\/code><\/pre>\n\n<p>It is possible to modify generated thumbnail links using the <code>pdf_thumbnails_link_shortcode<\/code>\nfilter. The following attributes are available:<\/p>\n\n<ul>\n<li><code>$html<\/code> - Generated HTML code to be displayed<\/li>\n<li><code>$attachmentId<\/code> - Sanitized ID of the PDF attachment<\/li>\n<li><code>$size<\/code> - Sanitized thumbnail size<\/li>\n<li><code>$atts<\/code> - <a href=\"https:\/\/codex.wordpress.org\/Shortcode_API#Handling_Attributes\">Shortcode attributes (not sanitized)<\/a><\/li>\n<li><code>$content<\/code> - Shortcode content (not sanitized)<\/li>\n<\/ul>\n\n<p>Example 2: Wrap thumbnail link in figure and append caption<\/p>\n\n<pre><code>add_filter('pdf_thumbnails_link_shortcode', function ($html, $attachmentId, $size, $atts, $content) {\n    return \"&lt;figure&gt;$html &lt;caption&gt;Click to open image $attachmentId&lt;\/caption&gt;&lt;\/figure&gt;\";\n}, 10, 5);\n<\/code><\/pre>\n\n<h3>TODO<\/h3>\n\n<p>Add generated image to media browser after upload.<\/p>\n\n<p>Outline of an implementation based on the javascript media API:<\/p>\n\n<pre><code>\/\/ New uploads\nwp.Uploader.queue.on('add', function (attachment) {\n\n    if (attachment.subtype !== 'pdf') {\n        return;\n    }\n\n    findThumbnailFor(attachment.ID).then(function (data) {\n\n        \/\/ Add attachment thumbnail to browser\n        var attachment = wp.media.model.Attachment.get(id)\n        attachment.fetch().done(function () {\n            wp.media.editor.open().state().get('library').add(generated attachment)\n        });\n\n    });\n});\n<\/code><\/pre>\n\n<p>Filter: ajax_query_attachments_args<\/p>\n\n<!--section=installation-->\n<p>PDF Thumbnails requires ImageMagick with GhostScript support. If you are lucky,\nthis is already installed on your system, otherwise, installation can be done\nwith the following steps:<\/p>\n\n<ol>\n<li>Install ghostscript<\/li>\n<li>Install imagemagick with ghostscript support<\/li>\n<li>Install PHP extension for imagemagick (can use pecl)<\/li>\n<li>Restart web server for changes to take effect<\/li>\n<\/ol>\n\n<p>Details may differ based on which operating system you are running, see\n<a href=\"https:\/\/wordpress.org\/support\/topic\/nothing-but-error-messages\">Support<\/a> for\nmore resources and tips on how this can be done in Windows, Linux and OSX.<\/p>\n\n<h4>Debian \/ Ubuntu<\/h4>\n\n<pre><code>sudo apt-get install ghostscript php5-imagick\nsudo service apache2 restart\n<\/code><\/pre>\n\n<!--section=changelog-->\n<p>This plugin use <a href=\"http:\/\/semver.org\/\">semantic versioning<\/a>, i.e. breaking changes\nincrease the MAJOR version.<\/p>\n\n<h4>2.2.0<\/h4>\n\n<ul>\n<li>Support title, target, and download attributes in <code>pdf_thumbnails_link<\/code> shortcode<\/li>\n<\/ul>\n\n<h4>2.1.0<\/h4>\n\n<ul>\n<li>Support thumbnail links with the <code>pdf_thumbnails_link<\/code> shortcode<\/li>\n<li>Support link customization using the <code>pdf_thumbnails_link_shortcode<\/code> filter<\/li>\n<\/ul>\n\n<h4>2.0.0<\/h4>\n\n<ul>\n<li>Replaced <code>pdf_thumbnails_before_get_image_blob<\/code> hook with <code>pdf_thumbnails_generate_image_blob<\/code> filter<\/li>\n<\/ul>\n\n<h4>1.0.2<\/h4>\n\n<ul>\n<li>Introduced <code>pdf_thumbnails_before_get_image_blob<\/code> hook<\/li>\n<\/ul>","raw_excerpt":"This plugin generates a thumbnail everytime you upload a PDF attachment. Generated thumbnail is an image of the first page in uploaded document.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/28669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=28669"}],"author":[{"embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/stianlik"}],"wp:attachment":[{"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=28669"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=28669"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=28669"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=28669"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=28669"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/srd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=28669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}