Download PDF using Spatie Laravel-PDF on table action
I am trying to download a PDF generated from a blade view. I tried DOMPDF and it works fine, but I would like to use Spatie's PDF which has better funcionality. I added the PDF to the table action, but the button just spins and nothing gets returned. Is there a way to convert the PDF to a stream to make it downloadable or?
Action::make('download')
->action(function (Invoice $record)
{
return pdf()->view('pdf.invoice', ['invoice' => $record])
->format('a4')
->name('your-invoice.pdf')
->download();
})
->iconButton('heroicon-o-document-arrow-down')
->icon('heroicon-o-document-arrow-down')
->label('Preuzmi PDF'),Solution
I managed to do it
return response()->streamDownload(function () use ($record) {
echo base64_decode(Pdf::view('pdf.invoice', ['invoice' => $record])
->format('a4')
->footerView('pdf.invoicefooter')
->name('your-invoice.pdf')
->base64());
}, 'test' . '.pdf');