How can I render a PDF using a Livewire component that implements HasInfolists?
I've built an abstract component called
App\Livewire\Pdf\Pdf
. This component implements HasInfolists
and HasForms
.
This component is being used as an abstract class for App\Livewire\Pdf\MembershipAgreement
. The class has its own blade file and headerInfolist
method.
I have successfully created a rendered HTML file that routed to {base_url}/pdf/agreement/membership/{record}
, using a typical render
method.
But when I tried to plug it in to \Barryvdh\DomPDF\Facade\Pdf
, it throws an exception.
In routes/web.php
:
This is how the error looks: https://flareapp.io/share/67OwQOJ7
Thank you for reading to this point. Please let me know if this problem comes from me, Livewire, or barryvdh/laravel-dompdf.Flare
Using $this when not in object context - The error occurred at https://dashboard.marsgym.test/pdf/agreement/membership/01hcye30x3nazdb1danprd728p/open
4 Replies
Did you solve the problem? I am also trying a similar process but so far no luck
I haven’t solved the issue. I just render the page and explicitly ask the users to hit Ctrl+P to print from the browser ¯\_(ツ)_/¯
@lazywaterpark if you change
$this->
to $record->
in blade file, what happens than?
Like
This is what works for me. I am developing a student application system, where student fill up the application, make payment for application fee and finally submit the application form. Once an application is submitted, we need to generate the pdf version of the application, save it to the disk and send it by email as attachment. So that is the context.
I made liveware component - this is only to generate the application pdf (not for showing to the student)
I am using Spatie's PDF facade. This seems to work quite well with the CSS. The blade file is at this moment
I can use tinker to open a session and use
I have not yet taken the CSS, but this gets the data and creates a PDF file with correct data. This should be good enough for me. I hope that this helps.
I have tested it out, with proper css. It works quite well.