Custom Action "Download PDF" button #5289
-
I am using this package: https://github.com/elibyy/tcpdf-laravel which is a wrapper for the original https://tcpdf.org/ I was using Metronic 8 for the project and after discovering Filament, I decided to give it a try and I'm very close to migrate my project into Filament. In the current project (Not Filament) I have 4 actions in the table (View, Edit, Delete, Download PDF): The PDF button is handed by TCPDF to convert inserted data to a PDF report once clicked ,like so: The content of the pdf button is a separate blade file called from the controller, so you may consider it as a "Custom HTML" How can I implement this action button in Filament? I didn't find a "Custom Actions" sections in the docs. Note that the PDF button should be within the View page also. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 11 replies
-
use Filament\Tables\Actions\Action;
class DownloadPdfAction extends Action
{
protected string $view = 'actions.download-pdf-view';
public static function make(?string $name = 'download-pdf'): static
{
return parent::make($name);
}
protected function setUp(): void
{
//...
}
} |
Beta Was this translation helpful? Give feedback.
-
You could use Livewire's file downloads Action::make('download')
->label('Download PDF')
->action(function ($record) {
// generate PDF here from the current $record
return response()->streamDownload(...);
}) https://laravel-livewire.com/docs/2.x/file-downloads#introduction |
Beta Was this translation helpful? Give feedback.
-
I decided to change TCPDF to domPDF as it's a lot easier (TCPDF is develop on top of domPDF anyways).
The code above brings me this error: When I What's the variable that returns the data? I couldn't find what I'm looking for in the documentation. Pointing me to it would be highly appreciated also. |
Beta Was this translation helpful? Give feedback.
-
Got it!!Instead of using domPDF needs a controller and a route in order to generate PDFs correctly. First off, create a route:
I created a route group called
This route is handled by the controller method:
Moving to Filament Resource
This way, the pdf generates as I want. |
Beta Was this translation helpful? Give feedback.
-
Hello friend. I have a question related to this, please allow me. In my filament project, I want to create a PDF after filtering the data. Ex. let's assume I have all together 10 order entries out of which 4 got delivered, now when I select 'Delivered' I want to create or download a pdf with delivered entries, not all the 10 records. I'm using DomPDF. |
Beta Was this translation helpful? Give feedback.
-
How do we send filter request to controller method ? |
Beta Was this translation helpful? Give feedback.
-
Hi I want to share my result inpired by this discussion. Then, the same concept but reusable: // Action
class PurchaseReportAction extends Action
{
use CanCustomizeProcess;
public static function getDefaultName(): ?string
{
return 'purchase report';
}
protected function setUp(): void
{
parent::setUp();
$this->label(__('purchase.report.provider.action.label'));
$this->icon('heroicon-o-document-text');
$this->url(fn (Purchase $record) => route('report.purchase', ['id' => $record->id], true));
}
}
// Usage in a Resource
public static function table(Table $table): Table
{
return $table
->columns([
// ...
])
->filters([
// ...
])
->actions([
Tables\Actions\ActionGroup::make([
PurchaseReportAction::make(),
Tables\Actions\EditAction::make(),
])->iconButton()
])
// ..
);
} Thank you! A hug. |
Beta Was this translation helpful? Give feedback.
Got it!!
Instead of using
->action()
, use->url()
domPDF needs a controller and a route in order to generate PDFs correctly.
First off, create a route:
I created a route group called
generate-pdf
so within it I will create routes that redirects to the controller which contains methods of generating different PDF files based on Filament resource. In my case I only have 1 for now which is:Route::get('incident-rep…