<p>You mixed in some code from the documentation resulting in a wrong variable name..</p>
<pre><code>{% set pdfBlocks = entry.inhaltMatrix.all() %}
    {% if pdfBlocks|length %}
        {% for block in pdfBlocks %}
            {% if block.type == &quot;pdf&quot; %}
                {% if block.pdfFile %}
                    {% set rel = block.pdfFile.one() %}
                    {% if rel %}
                        &lt;a href=&quot;{{ rel.url }}&quot;&gt;{{ rel.title }}&lt;/a&gt;
                        &lt;img src=&quot;{{ craft.PDFThumb.thumbnail(rel) }}&quot;&gt;
               
                    {% endif %}
                {% endif %}
            {% endif %} 
       {% endfor %}
{% endif %}
</code></pre>
<p>Also be sure to go to the plugins settings and set the appropriate assets paths.</p>

CC BY-SA 4.0
2021-02-20T19:25:10.983Z
Thanks, that helps me understand the variable, but it still doesn't work. The plugin creates the `preview` folder for the thumbs, but doesn't create the thumbs. I've double checked paths, permissions, and that ImageMagik is installed, but for whatever reason it won't create the thumbnail. Tried on MAMP and an Arcustech server.
doctorgloom
CC BY-SA 4.0
2021-02-21T09:04:08.180Z
Does it generate an url for the image asset? Also double-check the volumes url and that the volume has public urls enabled.
MisterMike
CC BY-SA 4.0
2021-02-22T18:46:07.197Z
Yes, it generates the url. Public is enabled (the actual PDF links work fine). I'm stumped. Perhaps the plugin doesn't work well with 3.6.x?
doctorgloom
CC BY-SA 4.0
2021-02-20T00:53:26.417Z
2021-02-20T00:53:26.417Z
MisterMike
<p>I would like to autogenerate a thumbnail of PDF's, and from <a href="https://craftcms.stackexchange.com/questions/2156/generate-pdf-preview-images-automatically">this question</a> I found the <a href="https://github.com/jmoont/pdfthumb#readme" rel="nofollow noreferrer">plugin PDFThumb</a>. The problem I'm running into is I'm relatively new to Craft, and I can't seem to figure out how to use the provided code when it is with a Matrix field.</p>
<p>As I said I'm new to this, and I usually end up tying myself in knots when trying to backtrack the variable references, and I think that's the problem here.</p>
<p>The reference code from the plugin repo:</p>
<pre><code>{% for myAsset in item.assetRef %}
    &lt;img src=&quot;{{ craft.PDFThumb.thumbnail(myAsset) }}&quot;&gt;
    &lt;img src=&quot;{{ craft.PDFThumb.thumbnail(myAsset, 100, 100) }}&quot;&gt;
    &lt;img src=&quot;{{ craft.PDFThumb.thumbnail(myAsset, 100, 150, true, 'jpg') }}&quot;&gt;
{% endfor %}
</code></pre>
<p>And my code:</p>
<pre><code>{% set pdfBlocks = entry.infoPagePDF.all() %}
{% if pdfBlocks|length %}
        {% for block in pdfBlocks %}
            {% if block.type == &quot;pdf&quot; %}
                {% if block.pdfFile %}
                    {% set rel = block.pdfFile.one() %}
                    {% if rel %}
                        &lt;a href=&quot;{{ rel.url }}&quot;&gt;{{ rel.title }}&lt;/a&gt;
                    {# Autogenerated Thumb #}
                        {% for myAsset in item.assetRef %}
                            &lt;img src=&quot;{{ craft.PDFThumb.thumbnail(myAsset) }}&quot;&gt;
                        {% endfor %}
                    {% endif %}
                {% endif %}
            {% endif %} 
       {% endfor %}
{% endif %}
                
</code></pre>
<p>The link generates fine, it's the image that doesn't.</p>
<p>I've tried a bunch of different variations, but the problem (I think) revolves around the fact I'm not sure what I'm supposed to be referencing in the <code>FOR</code>(myAsset and item.assetRef), so for clarity I reset my attempts to the provided code example.</p>

<matrix><plugins>
Autogenerated PDF Thumbnail using PDFThumb in a Matrix Field
# Autogenerated PDF Thumbnail using PDFThumb in a Matrix Field

(Asked by: username_0 on 2021-02-19)

I would like to autogenerate a thumbnail of PDF's, and from this question I found the plugin PDFThumb. The problem I'm running into is I'm relatively new to Craft, and I can't seem to figure out how to use the provided code when it is with a Matrix field.
As I said I'm new to this, and I usually end up tying myself in knots when trying to backtrack the variable references, and I think that's the problem here.
The reference code from the plugin repo:
{% for myAsset in item.assetRef %}
    
    
    
{% endfor %}

And my code:
{% set pdfBlocks = entry.infoPagePDF.all() %}
{% if pdfBlocks|length %}
        {% for block in pdfBlocks %}
            {% if block.type == "pdf" %}
                {% if block.pdfFile %}
                    {% set rel = block.pdfFile.one() %}
                    {% if rel %}
                        {{ rel.title }}
                    {# Autogenerated Thumb #}
                        {% for myAsset in item.assetRef %}
                            
                        {% endfor %}
                    {% endif %}
                {% endif %}
            {% endif %} 
       {% endfor %}
{% endif %}
                

The link generates fine, it's the image that doesn't.
I've tried a bunch of different variations, but the problem (I think) revolves around the fact I'm not sure what I'm supposed to be referencing in the FOR(myAsset and item.assetRef), so for clarity I reset my attempts to the provided code example.

**Tags:** matrix, plugins


---

## 1 answers

### Answer by username_1 on 2021-02-20. Score: 2

You mixed in some code from the documentation resulting in a wrong variable name..
{% set pdfBlocks = entry.inhaltMatrix.all() %}
    {% if pdfBlocks|length %}
        {% for block in pdfBlocks %}
            {% if block.type == "pdf" %}
                {% if block.pdfFile %}
                    {% set rel = block.pdfFile.one() %}
                    {% if rel %}
                        {{ rel.title }}
                        
               
                    {% endif %}
                {% endif %}
            {% endif %} 
       {% endfor %}
{% endif %}

Also be sure to go to the plugins settings and set the appropriate assets paths.

> **Comments:**
> **username_0**: Thanks, that helps me understand the variable, but it still doesn't work. The plugin creates the `preview` folder for the thumbs, but doesn't create the thumbs. I've double checked paths, permissions, and that ImageMagik is installed, but for whatever reason it won't create the thumbnail. Tried on MAMP and an Arcustech server.  
> **username_1**: Does it generate an url for the image asset? Also double-check the volumes url and that the volume has public urls enabled.  
> **username_0**: Yes, it generates the url. Public is enabled (the actual PDF links work fine). I'm stumped. Perhaps the plugin doesn't work well with 3.6.x?  

---

