Installation:
composer require print-filament/print
php artisan vendor:publish --tag="print-config" # Publish config (optional)
php artisan vendor:publish --tag="print-views" # Publish views (optional)
Register the Plugin:
Add to app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\PrintFilament\Print\PrintPlugin::make(),
]);
}
First Use Case:
Add the print button to a Filament page (e.g., Resource/Pages/ListRecords.php):
use PrintFilament\Print\PrintComponent;
public function getHeaderActions(): array
{
return [
PrintComponent::make("print_records")->label("Print"),
];
}
Printing Records:
Use PrintComponent in ListRecords or EditRecord pages to print filtered/selected data:
PrintComponent::make("print_invoices")
->label("Print Invoices")
->query(fn () => Invoice::query()->where('status', 'paid'))
->columns(['id', 'amount', 'date'])
->title("Paid Invoices Report");
Custom Styling:
Publish views (php artisan vendor:publish --tag="print-views") and override:
resources/views/vendor/print-filament/print/print.blade.php.print-styles in your CSS for printer-specific tweaks.Dynamic Data:
Pass dynamic data via data():
PrintComponent::make("print_custom")
->data(fn () => ['user' => auth()->user(), 'date' => now()])
->view('filament.print.custom');
Integration with Filament Actions:
Combine with Filament’s Action system for conditional printing:
use Filament\Actions\Action;
Action::make('print')
->label('Print Selected')
->icon('heroicon-o-printer')
->action(fn (Table $table) => PrintComponent::make("print_selected")->records($table->getSelectedRecords()))
->visible(fn (Table $table) => $table->hasSelectedRecords()),
CSS Inconsistencies:
@media print in your global CSS:
@media print {
.no-print { display: none; }
table { page-break-inside: avoid; }
}
Large Data Performance:
PrintComponent::make("print_large")
->query(fn () => Model::query()->paginate(50))
->perPage(50);
Filament Widgets:
Chart, StatsOverview) may not render correctly in print. Exclude them:
PrintComponent::make("print_dashboard")
->excludeWidgets(['chart_widget', 'stats_widget']);
Configuration Overrides:
config/print.php) may conflict with Filament’s caching. Clear cache after changes:
php artisan optimize:clear
Ctrl+Shift+P > "Show Print Preview") to debug rendering issues.config/print.php:
'debug' => env('PRINT_DEBUG', false),
box-shadow) are ignored in print. Test with actual printers or PDF generation tools.Custom Views: Override the print template by publishing views and extending:
PrintComponent::make("print_custom")
->view('filament.print.custom');
Example template (resources/views/filament/print/custom.blade.php):
@extends('print-filament::print.print')
@section('content')
<h1>Custom Print Title</h1>
{{ $data['user']->name }}
@endsection
Headless Printing: Use JavaScript to trigger print programmatically (e.g., after export):
window.printFilament = {
print: function (options) {
// Custom logic (e.g., open in new tab with print styles)
window.open(`/print?${options}`, '_blank').focus();
}
};
PDF Generation:
Combine with barryvdh/laravel-dompdf for PDF exports:
use Barryvdh\DomPDF\Facade\Pdf;
PrintComponent::make("print_pdf")
->action(fn () => Pdf::loadView('filament.print.pdf')->stream('report.pdf'));
How can I help you explore Laravel packages today?