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

Published 11 months ago by Crazylife

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
11 months ago (246,030 XP)

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

Crazylife

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

tisuchi

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

Crazylife

@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

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.