dompdf 添加到附件 Laravel

问题描述 投票:0回答:1

我想将 pdf 文件保存在 laravel 中而不是下载它,以便在创建邮件时可以附加它。

在文档中似乎找不到保存功能。

$document = new Dompdf($options);

//echo $output;

$document->loadHtml($html);

//set page size and orientation

$document->setPaper('a4', 'portrait');

//Render the HTML as PDF
$document->render();

$pdf = $document->output();

//define the receiver of the email
$to = '[email protected]';
$subject = 'SUBJECT -';
$repEmail = '[email protected]';

$fileName = 'filename.pdf';
$fileatt = $document->Output($fileName, 'E');
$attachment = chunk_split($fileatt);


// Send the email
SendMail::send('mail_templates.default', $data , function ($message) use ($attachment) {
    $eol = PHP_EOL;

    $message->from('[email protected]', 'Laravel');

    $message->to('[email protected]')->cc('[email protected]');

    $message->attach($attachment.$eol);
});
laravel dompdf
1个回答
0
投票

您可以按照文档中的指定使用它

  Pdf::loadHTML($html)->setPaper('a4', 'landscape')->setWarnings(false)->save('myfile.pdf')

包含您的代码的示例将如下所示

//specify the storage location 

 $filePath = storage_path().'/app/Mydocument/'.$now.'.pdf';       
  $document->loadHtml($html);
  $document->save($filePath);

© www.soinside.com 2019 - 2024. All rights reserved.