Export pdf with custom layout

hi, i want an action that give me the possibility to export a pdf of a user data. I just have those data and also custom template. But how can i export in pdf ? And what if fot have this action Bulk? how could i do?
12 Replies
Tetracyclic
Tetracyclic6mo ago
You'd need to make a custom action for this. You could use the code for the main Export action as a starting point for handling the (though you probably won't need a lot of it): https://github.com/filamentphp/filament/tree/3.x/packages/actions/src/Exports And use something like laravel-pdf to generate the PDF
ocram82
ocram82OP6mo ago
yes for sure, but what i have to put in it? i have to dispatch a job that build pdf?
Tetracyclic
Tetracyclic6mo ago
You don't have to dispatch a job, you could handle it within the request, but depending on the amount of data and the complexity of the PDF, it could take a while to complete, so dispatching a job makes sense. The built-in Export action splits the export into multiple jobs, each handling a maximum number of records (chunk), to reduce overall memory usage. However this would be tricky to do with a PDF, where you need all the data at once when you generate it.
ocram82
ocram82OP6mo ago
the pdf is about a user, and his relationship and it takes pictures also. Is something like this
No description
Tetracyclic
Tetracyclic6mo ago
Ah yeah, if it's just for a single user it can probably be done within the request, or just a single job.
ocram82
ocram82OP6mo ago
no ok, this is for a single user, but the nice to have is a bulk action
Tetracyclic
Tetracyclic6mo ago
Would the bulk action generate a single PDF with multiple users in it, or multiple PDFs, one for each user?
ocram82
ocram82OP6mo ago
what code i have to use? i just use an export action to export csv and i make this:
->headerActions([
ExportAction::make()
->exporter(UserExporter::class)
->formats([
ExportFormat::Csv,
])
->fileDisk('local')
->label('Export')
->icon('heroicon-o-document-text')
->color('primary')
->before(function (ModelsResource $resource) {
$resource->deleteOldExports();
}),

]);
->headerActions([
ExportAction::make()
->exporter(UserExporter::class)
->formats([
ExportFormat::Csv,
])
->fileDisk('local')
->label('Export')
->icon('heroicon-o-document-text')
->color('primary')
->before(function (ModelsResource $resource) {
$resource->deleteOldExports();
}),

]);
Do you mean this? one pdf with user data for different users
Tetracyclic
Tetracyclic6mo ago
You could try creating a custom exporter and export job and passing them to the ExportAction: https://filamentphp.com/docs/3.x/actions/prebuilt-actions/export#customizing-the-export-job
Tetracyclic
Tetracyclic6mo ago
Alternatively, you'd need to create a completely custom action that triggers the process, and your own code for creating the PDF that the action calls.
ocram82
ocram82OP6mo ago
ok thanks a lot! i will try and get you back some feedback
Tetracyclic
Tetracyclic6mo ago
It probably makes sense to do it from scratch, but use the existing code for inspiration, as it will be quite different doing it as a PDF, rather than as a spreadsheet of rows/columns
Want results from more Discord servers?
Add your server