I wanted to save the pdf file in the laravel rather than download it so it can be attach when creating a mail.
Cant seem to find a save function in the documentation.
$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);
});
2
Answers
You can use this as specified in the documention
a sample with your code will look like this
use IlluminateSupportFacadesStorage;
$fPath = ‘pdfs/’ . time() . ‘filename.pdf’; // path
Storage::disk(‘public’)->put($fPath, $pdf->output());