Ad

October CMS - DynamicPDF Plugin Fails

- 1 answer

I've installed the DynamicPDf plugin by Renatio in order to generate PDF as attachment in emails.
But I can't get it to work.

use Renatio\DynamicPDF\Classes\PDF; // import facade

  ...

$temp_file = tempnam(sys_get_temp_dir(), 'inv');
PDF::loadTemplate('renatio::invoice')->save($temp_file);

Mail::send('acme.blog::mail.welcome', $data, function ($message) {
    $message->attach($temp_file, ['as' => 'Your_Invoice.pdf']);
});

I keep getting the same error

No query results for model [Renatio\DynamicPDF\Models\Template]

Can someone help me ?

Update // Here's my code

<?php namespace Codalia\Membership\Helpers;

use October\Rain\Support\Traits\Singleton;
use Renatio\DynamicPDF\Classes\PDF; // import facade
use Codalia\Membership\Models\Member;

   ...

class EmailHelper
{
    use Singleton;

   ...

    public function payment($recordId, $data)
    {
        $member = Member::find($recordId);
        $vars = ['first_name' => $member->first_name,
                 'last_name' => $member->last_name,
                 'amount' => $data['amount'],
                 'item' => $data['item'],
                 'payment_mode' => $data['mode'],
        ];

        $temp_file = tempnam(sys_get_temp_dir(), 'inv');
        PDF::loadTemplate('renatio::invoice-membership', $vars)->save($temp_file);

        Mail::send('codalia.membership::mail.payment_email, $vars, function($message) use($member, $temp_file) {
            $message->to($member->email, 'Admin System');
            $message->subject(Lang::get('codalia.membership::lang.email.payment_subject));
            $message->attach($temp_file, ['as' => 'Your_Invoice.pdf']);
        });
      }

   ...

}
Ad

Answer

Ok I got it.

    $vars = ['amount' => 1.00, 'item' => 'stuff'];
    $temp_file = tempnam(sys_get_temp_dir(), 'inv');
    PDF::loadTemplate('invoice-membership', $vars)->save($temp_file);

The renatio:: part is useless here as it refers to a template as a file (ie: PDF views). Since I create my templates in the backoffice (ie: PDF templates), all data is stored in database.
But I have to say that the official documentation is poorly documented regarding this point. They should be more specific about how to use the methods with the PDF templates.

Ad
source: stackoverflow.com
Ad