F
Filament3mo ago
CappaS

Download in PDF my filament page (with all css and features) (ctr+P is not working well)

I'm trying to download my view in a PDF file but it doesn't work. I'm inside the Model file, Proposal Model. 1- I tried like this and works 100% well: return Action::make('downloadPdf')->action(function () { return response()->streamDownload(function () { $pdf = App::make('dompdf.wrapper'); $pdf->loadHTML('<h1>Hello</h1>'); echo $pdf->stream(); }, 'proposal.pdf'); }); 2- So I tried using my filament view and didn't work: return Action::make('downloadPdf')->action(function () { return response()->streamDownload(function () { $html = view('filament.user.resources.proposals.preview', ['record' => $this])->render(); $pdf = App::make('dompdf.wrapper'); $pdf->loadHTML($html); echo $pdf->stream(); }, 'proposal-'.$this->id.'.pdf'); }); The error is: Using $this when not in object context 3- Then, I tried only a Livewire file, and it worked, but without any filament feature (like buttons) and no css at all: return Action::make('downloadPdf')->action(function () { return response()->streamDownload(function () { $html = view('livewire.pages.user.proposal.preview', ['record' => $this])->render(); $pdf = App::make('dompdf.wrapper'); $pdf->loadHTML($html); echo $pdf->stream(); }, 'proposal-'.$this->id.'.pdf'); }); How can I do it? I just need to print the view that I'm seeing on my screen.
5 Replies
toeknee
toeknee3mo ago
return response()->streamDownload(function () use ($file) {
echo $file;
}, $filename);
return response()->streamDownload(function () use ($file) {
echo $file;
}, $filename);
With the file being the file. Is how I was using it
CappaS
CappaS3mo ago
hmmm It doesn't work too. Because my problem is creating the variable $file. Cause I'm using $this to render the view()
CappaS
CappaS3mo ago
No description
CappaS
CappaS3mo ago
How to print in PDF a rendered filament page
Kitty
Kitty2mo ago
I'm having the a similar issue with tables. See https://github.com/filamentphp/filament/discussions/12562 incase someone answers it
GitHub
Table in PDF on custom page not working · filamentphp filament · Di...
Package Table builder Package Version v3.0.0 How can we help you? I have a custom page with a table that I am trying to download as a PDF. The custom page includes a filament table and some other c...
Want results from more Discord servers?
Add your server
More Posts