skip to Main Content

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


  1. You can use this as specified in the documention

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

    a sample with your code will look like this

    //specify the storage location 
    
     $filePath = storage_path().'/app/Mydocument/'.$now.'.pdf';       
      $document->loadHtml($html);
      $document->save($filePath);
    
    
    Login or Signup to reply.
  2. use IlluminateSupportFacadesStorage;

    $fPath = ‘pdfs/’ . time() . ‘filename.pdf’; // path
    Storage::disk(‘public’)->put($fPath, $pdf->output());

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search