<p>Following the Digital download docs you may need the file path, so in order to get the file path in Enupal Snapshot you may need to return the <a href="https://enupal.com/craft-plugins/enupal-snapshot/docs/advanced/return-asset-model" rel="nofollow noreferrer">asset model</a> of the PDF:</p>

<pre><code>{%  set settings = {
        filename: 'my-first-pdf.pdf',
        inline: false,
        asModel: true
    }
%}

{% set assetModel = craft.enupalsnapshot.displayTemplate("reports/pdf-report", settings) %}

{# Digital Download code #}
{% set token = craft.digitalDownload.createToken(assetModel, options) %}

&lt;a href="{{ craft.digitalDownload.url(token) }}"&gt;{{ assetModel.filename}}&lt;/a&gt;
</code></pre>

CC BY-SA 4.0
2019-11-27T13:55:31.757Z
Hi @LindseyD - no thoughts on this?
Dan Lee
CC BY-SA 4.0
2019-11-28T14:57:30.637Z
Hi @DanLee are you sure you're passing the following settings?

inline: false,
asModel: true
Andre L.
CC BY-SA 4.0
2019-11-28T15:22:13.293Z
Hi @DanLee I also updated the example the filePath is not needed. We just need to pass the assetModel instead.
Andre L.
CC BY-SA 4.0
2019-11-29T10:01:04.740Z
@AndreL. I am using the settings - see my code above. I made the changes regarding the filePath as you suggest. I now get an error that says "Variable "options" does not exist."
Dan Lee
CC BY-SA 4.0
2019-12-01T21:37:59.800Z
@DanLee What are your Craft CMS and Snapshot versions?
Andre L.
CC BY-SA 4.0
2019-12-03T11:35:10.743Z
Craft 3.3.9 and the latest version of Snapshot
Dan Lee
CC BY-SA 4.0
2019-12-03T20:27:54.383Z
@DanLee `options` does not exist because you didn't specify a value for it. You can either specify an [array of options](https://www.doublesecretagency.com/plugins/digital-download/docs/creating-a-token), or remove that parameter from your `createToken` call.
Lindsey D
CC BY-SA 4.0
2019-12-04T11:15:20.750Z
Thanks that worked! If you want to update your answer I will accept it.
Dan Lee
CC BY-SA 4.0
2019-11-19T16:22:05.673Z
Thanks for the support Andre - unfortunatly I get a "Impossible to invoke a method ("getPath") on a string variable"  highlighting {% set filePath = assetModel.getPath() %}

I have updated my full code above.
Dan Lee
CC BY-SA 4.0
2019-11-19T22:28:59.130Z
Hi @DanLee, author of Digital Download here. I've (belatedly) replied to you [on Github](https://github.com/doublesecretagency/craft-digitaldownload/issues/5#issuecomment-555745226). If Enupal Snapshot is generating a real Asset, then you should be able to use Digital Download normally.
Lindsey D
CC BY-SA 4.0
2019-11-20T09:17:50.817Z
Thanks @LindseyD - I think Andre has picked up the same thing. I believe I'm almost there with the soloution - I just need to get the implimentation right.Any suggestions Andre on the error I'm getting above?
Dan Lee
CC BY-SA 4.0
2019-11-19T13:39:08.233Z
2019-11-28T15:20:59.943Z
2019-11-28T15:20:59.943Z
Andre L.
<p>I recently purchased the Digital Download plugin for Craft.</p>

<p>I'm wanting to secure a PDF download generated by another plugin called Enupal Snapshot. Reviewing the <a href="https://www.doublesecretagency.com/plugins/digital-download/docs/displaying-a-link" rel="nofollow noreferrer">Digital Download documentation</a> I'm not entirely sure how I would do that using the following code which generates the PDF on the fly?</p>

<p><strong>Update 1</strong></p>

<p>Advice has been given that we need to provide the file path. In order to get the file path in Enupal Snapshot you need to return the asset model of the PDF.</p>

<p><strong>Update 2</strong></p>

<p>The code was changed to reflect asset model requirment. Unfortunatly I get a "<strong>Impossible to invoke a method ("getPath") on a string variable</strong>" highlighting <code>{% set filePath = assetModel.getPath() %}</code> in the code.</p>

<p><strong>Code</strong></p>

<pre><code>{% set pdfName = 'now'|date('Y-m-d') ~ '-' ~ date().timestamp ~ '-evaluation-' ~ companyName ~ '-' ~ firstName ~ '-' ~ lastName ~ '-' ~ submissionId ~ random(50, 500) ~ '.pdf' %}

{% set assetFolderRef = evaluationSettings.evaluationAssetRef %}
{%
    set settings = {
        filename: pdfName,
        inline: false,
        overrideFile: true,
        asModel: true,
        singleUploadLocationSource: assetFolderRef,
        cliOptions: {
            'header-html': 'evaluation-tools/evaluation/pdf-header',
            'footer-html': 'evaluation-tools/evaluation/pdf-footer',
            'orientation': 'Portrait',
            'page-size': 'A4',
            'title': 'Evaluation for ' ~ companyName,
        },
        variables: {
            passSubmissionId: submissionId,
        }
    }
%}

{% set assetModel = craft.enupalsnapshot.displayTemplate("evaluation-tools/evaluation/pdf-report", settings) %}
{% set token = craft.digitalDownload.createToken(assetModel, options) %}

&lt;a href="{{ craft.digitalDownload.url(token) }}" class="f6 link white bg-animate bg-teal hover-bg-white hover-teal br-pill bn w-auto ph4 pv3 tc b pointer mb3"&gt;
    &lt;i class="fas fa-file-download"&gt;&lt;/i&gt; Download Report
&lt;/a&gt;
</code></pre>

<craft3><plugin-digitaldownload>
Securing a Generated PDF
# Securing a Generated PDF

(Asked by: username_0 on 2019-11-19)

I recently purchased the Digital Download plugin for Craft.
I'm wanting to secure a PDF download generated by another plugin called Enupal Snapshot. Reviewing the Digital Download documentation I'm not entirely sure how I would do that using the following code which generates the PDF on the fly?
Update 1
Advice has been given that we need to provide the file path. In order to get the file path in Enupal Snapshot you need to return the asset model of the PDF.
Update 2
The code was changed to reflect asset model requirment. Unfortunatly I get a "Impossible to invoke a method ("getPath") on a string variable" highlighting {% set filePath = assetModel.getPath() %} in the code.
Code
{% set pdfName = 'now'|date('Y-m-d') ~ '-' ~ date().timestamp ~ '-evaluation-' ~ companyName ~ '-' ~ firstName ~ '-' ~ lastName ~ '-' ~ submissionId ~ random(50, 500) ~ '.pdf' %}

{% set assetFolderRef = evaluationSettings.evaluationAssetRef %}
{%
    set settings = {
        filename: pdfName,
        inline: false,
        overrideFile: true,
        asModel: true,
        singleUploadLocationSource: assetFolderRef,
        cliOptions: {
            'header-html': 'evaluation-tools/evaluation/pdf-header',
            'footer-html': 'evaluation-tools/evaluation/pdf-footer',
            'orientation': 'Portrait',
            'page-size': 'A4',
            'title': 'Evaluation for ' ~ companyName,
        },
        variables: {
            passSubmissionId: submissionId,
        }
    }
%}

{% set assetModel = craft.enupalsnapshot.displayTemplate("evaluation-tools/evaluation/pdf-report", settings) %}
{% set token = craft.digitalDownload.createToken(assetModel, options) %}


     Download Report

**Tags:** craft3, plugin-digitaldownload


---

## 1 answers

### Answer by username_1 on 2019-11-19. Score: 2

Following the Digital download docs you may need the file path, so in order to get the file path in Enupal Snapshot you may need to return the asset model of the PDF:
{%  set settings = {
        filename: 'my-first-pdf.pdf',
        inline: false,
        asModel: true
    }
%}

{% set assetModel = craft.enupalsnapshot.displayTemplate("reports/pdf-report", settings) %}

{# Digital Download code #}
{% set token = craft.digitalDownload.createToken(assetModel, options) %}

{{ assetModel.filename}}

> **Comments:**
> **username_0**: Thanks for the support Andre - unfortunatly I get a "Impossible to invoke a method ("getPath") on a string variable"  highlighting {% set filePath = assetModel.getPath() %}  I have updated my full code above.  
> **username_2**: Hi @DanLee, author of Digital Download here. I've (belatedly) replied to you [on Github](https://github.com/doublesecretagency/craft-digitaldownload/issues/5#issuecomment-555745226). If Enupal Snapshot is generating a real Asset, then you should be able to use Digital Download normally.  
> **username_0**: Thanks @LindseyD - I think Andre has picked up the same thing. I believe I'm almost there with the soloution - I just need to get the implimentation right.Any suggestions Andre on the error I'm getting above?  
> **username_0**: Hi @LindseyD - no thoughts on this?  
> **username_1**: Hi @DanLee are you sure you're passing the following settings?  inline: false, asModel: true  
> **username_1**: Hi @DanLee I also updated the example the filePath is not needed. We just need to pass the assetModel instead.  
> **username_0**: @AndreL. I am using the settings - see my code above. I made the changes regarding the filePath as you suggest. I now get an error that says "Variable "options" does not exist."  
> **username_1**: @DanLee What are your Craft CMS and Snapshot versions?  
> **username_0**: Craft 3.3.9 and the latest version of Snapshot  
> **username_2**: @DanLee `options` does not exist because you didn't specify a value for it. You can either specify an [array of options](https://www.doublesecretagency.com/plugins/digital-download/docs/creating-a-token), or remove that parameter from your `createToken` call.  
> **username_0**: Thanks that worked! If you want to update your answer I will accept it.  

---

