<p>There a plugin for that:</p>

<p><a href="https://github.com/carnesmedia/pthumb" rel="nofollow">https://github.com/carnesmedia/pthumb</a></p>

<p>PThumb is a Craft plugin that generates thumbnail preview images for PDF documents. It's easy to drop into your templates, requires only the commmand-line version of ImageMagick (not the PHP bindings), and caches the generated thumbnails.</p>

<pre><code>&lt;img src="{{ craft.PThumb.thumbnail(myAsset) }}"&gt;
&lt;img src="{{ craft.PThumb.thumbnail(myAsset, 100, 100) }}"&gt;
&lt;img src="{{ craft.PThumb.thumbnail(myAsset, 100, 150, true, 'jpg') }}"&gt;
</code></pre>

CC BY-SA 3.0
2014-08-26T07:58:24.877Z
2014-08-26T07:58:24.877Z
Johannes Lamers
<p>Is it possible to auto generate PDF preview images with Craft transforms? <a href="https://stackoverflow.com/q/467793/3699394">This popular Q/A</a> at Stack Overflow shows a PHP solution making use of <a href="https://www.php.net/imagick" rel="nofollow noreferrer">ImageMagick</a> and <a href="http://sourceforge.net/projects/ghostscript/" rel="nofollow noreferrer">GhostScript</a>. Is installing these plugins all I'd need to make Craft do the transforms with <code>pdf.getUrl('thumb')</code>?</p>
<p>Currently I use an assets - <a href="http://buildwithcraft.com/docs/assets#asset-meta-fields" rel="nofollow noreferrer">asset meta field</a> on the PDF to achieve what I want (see code below), but that means I have to generate and upload the image myself. So I wondered if there's a nice and easy way to automate that process.</p>
<pre><code>{% for pdf in entry.pdfAssets %}

    {# Get the pdf preview thumb or use a generic one as a fallback #}
    {% set previewImage = pdf.previewImage|length ? pdf.previewImage.first.url('thumb') : 'pdf_thumb.jpg' %}
    
    &lt;a href=&quot;{{ pdf.url }}&quot; target=&quot;_blank&quot;&gt;
        &lt;img src=&quot;{{ previewImage }}&quot;&gt;
    &lt;/a&gt;

{% endfor %}
</code></pre>

<assets><image-transforms>
Generate PDF preview images automatically?
# Generate PDF preview images automatically?

(Asked by: username_0 on 2014-08-26)

Is it possible to auto generate PDF preview images with Craft transforms? This popular Q/A at Stack Overflow shows a PHP solution making use of ImageMagick and GhostScript. Is installing these plugins all I'd need to make Craft do the transforms with pdf.getUrl('thumb')?
Currently I use an assets - asset meta field on the PDF to achieve what I want (see code below), but that means I have to generate and upload the image myself. So I wondered if there's a nice and easy way to automate that process.
{% for pdf in entry.pdfAssets %}

    {# Get the pdf preview thumb or use a generic one as a fallback #}
    {% set previewImage = pdf.previewImage|length ? pdf.previewImage.first.url('thumb') : 'pdf_thumb.jpg' %}
    
    
        
    

{% endfor %}

**Tags:** assets, image-transforms

---

## 1 answers

### Answer by username_1 on 2014-08-26. Score: 4 | Accepted answer

There a plugin for that:
https://github.com/carnesmedia/pthumb
PThumb is a Craft plugin that generates thumbnail preview images for PDF documents. It's easy to drop into your templates, requires only the commmand-line version of ImageMagick (not the PHP bindings), and caches the generated thumbnails.


---

