Hi.
I am using code below to render PDF file. This way I can download it using button in backend for example.
public function getBasicPDF($model_id)
{
$model = MyModel::where('id',$model_id)->first();
// variables
$dompdfConfig = Config::get('company.something::dompdf', ['defines' => []]);
$dompdf = new Dompdf($dompdfConfig['defines']);
$template = File::get(plugins_path('company/mgshopcmsadv/views/partials/contractwithdrawal-pdf.htm'));
$layoutVariables = [
'model' => $model,
'logopath' => plugins_path('company/something/assets/img/logo.png'),
];
// Render the template
$renderedHtml = Twig::parse($template, $layoutVariables);
$dompdf->loadHtml($renderedHtml);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$output = $dompdf->output();
$fileName = 'odstupenie_od_zmluvy-'.$model->id.'.pdf';
return ['content' => $output, 'filename' => $fileName];
}
I have problem sending it via email if I want to use Mail::later(). Code is
Mail::later(2, 'company.pluginname::mail.admin-withdrawalfromcontractform', $vars, function($message) use ($to, $otherAdmins, $pdfData) {
$message->to($to, $to);
foreach($otherAdmins as $item){
$message->cc($item['email'], $item['email']);
}
$message->attachData($pdfData['content'], $pdfData['filename'], [
'mime' => 'application/pdf',
]);
});
I am always getting error.
Unable to JSON encode payload. Error (5): Malformed UTF-8 characters, possibly incorrectly encoded" on line 110 of /home/html/metalprodukt.sk/public_html/vendor/laravel/framework/src/Illuminate/Queue/Queue.php
When sending email using Mail::send() all is fine. Is it possible to send email PDF attachment without creating actual file ?
Reason why I don’t want to save file is I want delete file after email is sent. I can’t use Mail::send() due I need to be sure job is created and send. I can’t rely on creating file and then deleting after some time, due SMTP can fail, so I need to be sure file was send.
Is this possible ?
Thank you