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
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
yes for sure, but what i have to put in it? i have to dispatch a job that build pdf?
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.
the pdf is about a user, and his relationship and it takes pictures also. Is something like this
Ah yeah, if it's just for a single user it can probably be done within the request, or just a single job.
no ok, this is for a single user, but the nice to have is a bulk action
Would the bulk action generate a single PDF with multiple users in it, or multiple PDFs, one for each user?
what code i have to use? i just use an export action to export csv and i make this:
Do you mean this?
one pdf with user data for different users
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-jobAlternatively, 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.
ok thanks a lot! i will try and get you back some feedback
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