Is there a method to convert a html page into pdf and attach pdf in email without save the pdf to storage?

Published 1 month ago by dreamxyz

I am using this method to send email

Mail::send('....')

I want to convert a html page to pdf format and send via email as attachment. Is there any method i can use for perform this?

jlrdw
jlrdw
1 month ago (199,820 XP)

Have you gone to https://github.com/barryvdh/laravel-dompdf and read their documentation?

dreamxyz

@jlrdw Can i convert it and send directly without store the pdf file somewhere else?

tisuchi
tisuchi
1 month ago (262,165 XP)

It seems that you can do it.

You can create a new DOMPDF instance and load a HTML string, file or view name. You can save it to a file, or stream (show in browser) or download.

Ref: https://github.com/barryvdh/laravel-dompdf#using

dreamxyz

@tisuchi i tried something like

   $pdf = PDF::loadHtml(URL::to(......));
   $m->attachData($pdf->output(), 'abc.pdf', ['mime' => 'application/pdf']);

When email sent out, the attachment is blank and only with the url link, is my way correct to make the html as pdf and send as email attachment?

tisuchi
tisuchi
1 month ago (262,165 XP)

It seems correct. As long as you are getting the pdf file, that should be fine.

Please sign in or create an account to participate in this conversation.