Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Print Laravel Package

print-filament/print

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. 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)
    
  2. Register the Plugin: Add to app/Providers/Filament/AdminPanelProvider.php:

    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                \PrintFilament\Print\PrintPlugin::make(),
            ]);
    }
    
  3. 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"),
        ];
    }
    

Implementation Patterns

Common Workflows

  1. 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");
    
  2. Custom Styling: Publish views (php artisan vendor:publish --tag="print-views") and override:

    • resources/views/vendor/print-filament/print/print.blade.php
    • Target .print-styles in your CSS for printer-specific tweaks.
  3. Dynamic Data: Pass dynamic data via data():

    PrintComponent::make("print_custom")
        ->data(fn () => ['user' => auth()->user(), 'date' => now()])
        ->view('filament.print.custom');
    
  4. 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()),
    

Gotchas and Tips

Pitfalls

  1. CSS Inconsistencies:

    • Browser print previews may ignore custom styles. Use @media print in your global CSS:
      @media print {
          .no-print { display: none; }
          table { page-break-inside: avoid; }
      }
      
    • Fix: Publish views and override the print template to enforce styles.
  2. Large Data Performance:

    • Printing thousands of records may freeze the browser. Use pagination or chunking:
      PrintComponent::make("print_large")
          ->query(fn () => Model::query()->paginate(50))
          ->perPage(50);
      
  3. Filament Widgets:

    • Widgets (e.g., Chart, StatsOverview) may not render correctly in print. Exclude them:
      PrintComponent::make("print_dashboard")
          ->excludeWidgets(['chart_widget', 'stats_widget']);
      
  4. Configuration Overrides:

    • Published config (config/print.php) may conflict with Filament’s caching. Clear cache after changes:
      php artisan optimize:clear
      

Debugging Tips

  • Inspect Print Output: Use browser dev tools (Ctrl+Shift+P > "Show Print Preview") to debug rendering issues.
  • Log Queries: Enable query logging in config/print.php:
    'debug' => env('PRINT_DEBUG', false),
    
  • Test with Real Printers: Some CSS properties (e.g., box-shadow) are ignored in print. Test with actual printers or PDF generation tools.

Extension Points

  1. 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
    
  2. 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();
        }
    };
    
  3. 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'));
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed