Pdf stream() doesn't work on submit() custom page
Hello, I have a custom page, where I have a search form, but I want a PDF to open when I click send. But it's not working, I guess it will be done another way, but I don't know which one. I need to open the pdf in another tab and that's it, I don't want to download it directly. Can somebody help me? thanks
Submit custom page:
public function submit()
{
$teacher = Employee::find($this->data['professor']);
$sessions = $teacher->sessions()->where('course_id', $this->data['course'])->get();
if (!$this->data['course']) {
return Notification::make()->duration(12000)->title("Selecciona un/a curs per seguir")->danger()->send();
}
if (count($sessions) == 0) {
return Notification::make()->duration(12000)->title("No hi ha sessions per generar informe")->danger()->send();
}
$pdf = PDF::loadView('pdf.report-hours-kms', ['data' => $sessions,'teacher' => $teacher]);
return $pdf->stream();
}
17 Replies
If you want it in a new tab, you need a normal browser link that opens a new page and that page streams the PDF.
Yeah I tend to use:
Thanks but If I do like toeknee, it downloads, what I want is for the pdf to open in the browser
Then, you can have a custom URL which allows you to stream it on a new page instead
But I'm not saving the pdf, I just want to show so that they decide to download or print, or have I misunderstood?
you can't show a pdf without saving it first. the browser has to have a url to show it. just like an image.
But in Laravel I have always shown it with $pdf->stream() without saving it. Is it a filament thing then? It's about learning why it happens, thanks
how were you displaying the stream?
In Laravel I always did like this:
$pdf = PDF::loadView('pdf.report-hours-kms', ['data' => $sessions,'teacher' => $teacher]);
return $pdf->stream();
They are building it with domPDF into tmp and steaming it basically
Yes, I use domPDF. P.D: I'm a woman π
Apologise for the assumption
There's no problem π
So you can do:
But I doubt you want that. So instead, move the PDF Building into a new controller and have the url of the action open the new url which contains the id of the file you are bullding? if it's live / on the fly, you will need to save it, view it and setup a command to auto-clear the tmp pdf folder
I think the issue is that you are in the context of a livewire request. Maybe some insight here. https://livewire.laravel.com/docs/wire-stream
Laravel
wire:stream | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
nevermind, the tag says your on v2. this won't help since stream is a livewire v3 feature.
Livewire handles streamed data as a download. That's just the way downloads in Livewire work. That's why you need a separate page where you stream the data, so you can open it in a new tab.