OctoberCMS DynamicPDF On前端失败

时间:2017-01-31 18:33:51

标签: octobercms dynamicpdf octobercms-plugins

我需要在OctoberCMS上使用前端的DynamicPDF插件提供一些帮助:

拥有以下10月CMS页面:

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>

预期的行为是在单击按钮时下载PDF文件,但它会无声地加载和死亡......什么也看不见。试过->download()->stream()但没有任何作用!

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

一种解决方法是创建专门用于PDF创建的新页面。

$(document).ready(function() {
    var mustSlideRight = true;
    var mustSlideLeft = false;
    $(window).scroll(function() {

        var scrolledHeight = ($(window).scrollTop());

        if (scrolledHeight > 2 && mustSlideRight)  {

            $(".scrollButton")
                .velocity({width: "55px", height: "55px"}, {duration: 200, easing: "ease-in-out"})
                .velocity({width: "0px", height: "0px", opacity: "0"}, {duration: 80, easing: "ease-in-out"})
                .velocity({left: "95%", backgroundPosition: "-50px"}, {duration: 1})
                .velocity({width: "55px", height: "55px", opacity: "1"}, {duration: 80, easing: "ease-in-out"})
                .velocity({width: "50px", height: "50px"}, {duration: 150, easing: "ease-in-out"});
            mustSlideRight = false;
            mustSlideLeft = true;
        }
        else if (scrolledHeight < 10 && mustSlideLeft) {

            $(".scrollButton")
                .velocity({width: "55px", height: "55px"}, {duration: 200, easing: "ease-in-out"})
                .velocity({width: "0px", height: "0px", opacity: "0"}, {duration: 80, easing: "ease-in-out"})
                .velocity({left: "49%", backgroundPosition: "0px"}, {duration: 1})
                .velocity({width: "55px", height: "55px", opacity: "1"}, {duration: 80, easing: "ease-in-out"})
                .velocity({width: "50px", height: "50px"}, {duration: 150, easing: "ease-in-out"});
            mustSlideLeft = false;
            mustSlideRight = true;
        }
    });

答案 1 :(得分:1)

你好Fernando Barrocal,

我注意到你的代码中有一个错误。您必须使用范围解析运算符来加载模板。

您的代码:

return PDF::loadTemplate("proj:invoice", ['data' => $account])->stream();

替换为:

return PDF::loadTemplate("proj::invoice", ['data' => $account])->stream();

希望这会对你有所帮助。

谢谢!