Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Syed1980's avatar

How do I generate a PDF of filtered results from the Filament project using DomPDF?

In my filament project I have a total of 10 entries in the database after filtering it reduces to 4 entries so now on a button click I want to generate a pdf only for these 4 entries, I'm getting all the 10 entries in the pdf.

0 likes
5 replies
Courtneydavis's avatar

Hello, To generate a PDF of filtered results from the Filament project using DomPDF, follow these steps:

Filter Data: Implement the filtering logic in your Filament project to reduce the database entries from 10 to 4 based on your specific criteria.

Create PDF View: Create a new view that displays the filtered results. This view should contain the HTML structure you want to convert into a PDF.

Integrate DomPDF: Install and integrate DomPDF into your project. You can use Composer to install it: composer require barryvdh/laravel-dompdf.

Generate PDF: In your controller or route handler https://www.mayoclinicpatientportals.com/ that handles the button click, retrieve the filtered data and pass it to the PDF view. Then, use DomPDF to generate the PDF from the view.

*use Dompdf\Dompdf; use Dompdf\Options;

public function generatePDF() { // Retrieve filtered data (4 entries) $filteredData = ... // Retrieve filtered data here

// Create PDF instance
$pdf = new Dompdf();
$options = new Options();
$options->set('isHtml5ParserEnabled', true);
$pdf->setOptions($options);

// Load the PDF view with filtered data
$pdf->loadView('pdf.filtered_view', ['data' => $filteredData]);

// Generate PDF
$pdf->render();

// Download or display the PDF
return $pdf->stream('filtered_results.pdf');

} * Create PDF View: In your resources/views/pdf directory, create a view file named filtered_view.blade.php. This view file should contain the HTML structure to display the filtered data.

Button Click: In your frontend, create a button that triggers the PDF generation route/controller when clicked.

amouchaldev's avatar

the solution is to use bulk action like this BulkAction::make('export')->action(fn (Collection $records) => redirect()->route('yourRouteName'))

visdb's avatar

Try this

Tables\Actions\BulkAction::make('generatePdf') ->label('Generate PDF') ->action(function ($records) { $pdf = Pdf::loadView('pdf.selected-items', ['records' => $records]); return response()->streamDownload(function () use ($pdf) { echo $pdf->output(); }, 'selected-items.pdf'); }) ->deselectRecordsAfterCompletion(),

Please or to participate in this conversation.