PHP code example of amjadiqbal / filament-record-pdf
1. Go to this page and download the library: Download amjadiqbal/filament-record-pdf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amjadiqbal / filament-record-pdf example snippets
use AmjadIqbal\FilamentRecordPdf\Actions\BulkDownloadPdfAction;
use AmjadIqbal\FilamentRecordPdf\Actions\DownloadPdfAction;
use AmjadIqbal\FilamentRecordPdf\Actions\EmailPdfAction;
use AmjadIqbal\FilamentRecordPdf\Actions\PreviewPdfAction;
use AmjadIqbal\FilamentRecordPdf\Actions\SavePdfAction;
use Filament\Actions\ActionGroup;
public static function table(Table $table): Table
{
return $table
->columns([/* ... */])
->recordActions([
ActionGroup::make([
PreviewPdfAction::make()->pdfView('pdf.invoice'),
DownloadPdfAction::make()->pdfView('pdf.invoice'),
EmailPdfAction::make()->pdfView('pdf.invoice')
->defaultRecipient(fn (Invoice $record) => $record->customer_email),
SavePdfAction::make()->pdfView('pdf.invoice')->saveToColumn('pdf_path'),
]),
])
->toolbarActions([
BulkDownloadPdfAction::make()->pdfView('pdf.invoice'),
]);
}
->pdfView('pdf.invoice') // string or fn (Model $record)
->pdfData(fn (Invoice $record) => [...]) // merged with ['record' => $record]
->pdfFilename(fn (Invoice $record) => "Invoice {$record->number}") // becomes invoice-inv-1042.pdf
->pdfFormat('letter') // a4 (default), letter, legal, a3, a5 ...
->pdfLandscape()
->pdfDriver('browsershot') // per action; the default comes from config
->modifyPdfUsing(fn (PdfBuilder $pdf, Invoice $record) => $pdf->margins(10, 10, 10, 10))
->pdfAbility(['downloadPdf', 'view']) // see Authorization
->authorizePdfUsing(fn (Invoice $record, ?User $user) => $user?->is($record->owner))
EmailPdfAction::make()
->defaultRecipient(fn (Invoice $record) => $record->customer_email)
->defaultSubject(fn (Invoice $record) => "Invoice {$record->number}")
->defaultMessage('Please find your invoice attached.')
->queueMail() // or set filament-record-pdf.mail.queue
// the closure can also take Model $record and array $data (the form values)
->sendUsing(fn (array $recipients, RecordPdfMail $mail) => Mail::mailer('postmark')->to($recipients)->send($mail));
SavePdfAction::make()
->disk('s3') // default: filament-record-pdf.disk (local)
->directory(fn (Invoice $record) => 'invoices/'.$record->issued_at->year)
->visibility('private')
->saveToColumn('pdf_path') // stores the path on the record
->overwrite(false) // keep old files and add a timestamp to the new one
->afterSaving(fn (Invoice $record, string $path, string $disk) => /* ... */);