Securing a Generated PDF 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) %}

&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;
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) %}

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