I have a function that will generate a pdf file then email it to someone. I tried to debug it using return view
first then when i saw it in the network tab, it is correct. But when I email it then I will view the pdf there, the pdf styles is not applied or rendered properly. Can someone tell me what should I do about this and what is the problem?
Here is my controller
$css = 'health/css/bootstrap.min.css';
$data_type = pathinfo($css, PATHINFO_EXTENSION);
$css_data = file_get_contents($css);
$path = 'health/img/logo.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
//return view('emails.form',compact('base64','css_data')); test
$pdf = \PDF::loadView('emails.form',compact('base64','css_data'));
$beautymail = app()->make(\Snowfire\Beautymail\Beautymail::class);
$beautymail->send('emails.welcome', [], function($message)use($pdf)
{
$message
->from('testemail@gmail.com','TEST')
->to('ronald.b@gmail.com', 'Test')
->attachData($pdf->output(), "asdf.pdf")
->subject('Welcome!');
});
When I tried to do first
return view('emails.form',compact('base64','css_data'));
What i get is the correct one, like this https://imgur.com/a/Dz7ifms
Then when i comment the return function and proceed to the email, what i get is like this https://imgur.com/a/mziXxxQ
I dont know what is happening. Please help if you got some idea. Thanks..
I figured it out that the package has many bugs in it. I tried to use wkhtmltopdf
which is for php and I saw a wrapper for laravel and i found it at github which is laravel-snappy
. I got good results and my answer was solved.
It has the same code structure with dompdf
but you have to download wkhtmltopdf
tool and save it to your computer in order to work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.