Reputation: 13172
I need some help here with OctoberCMS using DynamicPDF Plugin on front end:
Have the following October CMS Page:
title = "Dues"
url = "/account/dues"
layout = "profile"
is_hidden = 0
==
<?php
use Corp\Proj\Models\Account;
use Renatio\DynamicPDF\Classes\PDF;
use Renatio\DynamicPDF\Models\PDFTemplate;
function onInvoiceDownload()
{
$id = post("id");
$account = Account::find($id);
return PDF::loadTemplate("proj:invoice", ['data' => $account])->stream();
}
?>
==
{% set account = user.account %}
<button data-request="onInvoiceDownload" data-request-data="id: {{ account.id }}" class="btn btn-default">
<i class="fa fa-download"></i> Download
</button>
The expected behaviour would be to download the PDF File when clicking the button, but it loads and dies silently ... doing nothing visible. Tried with ->download()
and ->stream()
but nothing works!
Any ideas ?
Upvotes: 0
Views: 676
Reputation: 21681
Hello Fernando Barrocal,
I noticed one mistake in your code. You have to use scope resolution operator to load template.
Your Code:
return PDF::loadTemplate("proj:invoice", ['data' => $account])->stream();
Replace With:
return PDF::loadTemplate("proj::invoice", ['data' => $account])->stream();
Hope this will helps you.
Thanks!
Upvotes: 1
Reputation: 846
one workaround is to create a new page dedicated to the PDF creation.
title = "PDF Dues"
url = "/account/dues/pdf/:id"
layout = "profile"
is_hidden = 0
==
<?php
use Corp\Proj\Models\Account;
use Renatio\DynamicPDF\Classes\PDF;
use Renatio\DynamicPDF\Models\PDFTemplate;
function onStart()
{
$id= $this->param('id');
$account = Account::find($id);
return PDF::loadTemplate("proj:invoice", ['data' => $account])->stream();
}
Upvotes: 1