Using form schema for PDF export
I'm building an application with a LOT of forms. I also need a full PDF export containing multiple forms.
The form definition is in a Filament form schema, obviously. The PDF export is built separately.
Can I extend the schema or form components to include PDF render functionality? That way I could just throw the same schema at it, and it can return the html needed for PDF print. I'd only need one source of the form schema, which is faster to build and schema changes wouldn't have to be applied twice.
Maybe some plugin does a similar extension?
Solution:Jump to solution
I've ultimately created quite a hacky solution for this. Overruling ViewComponent.php via composer. If anyone would like more details, let me know.
4 Replies
I guess I'd have to mimic the way Filament renders it forms, but offer it a different set of blade files. That way I can reuse layout components, conditional fields, etc.
Anyone who has experience with something like this?
Solution
I've ultimately created quite a hacky solution for this. Overruling ViewComponent.php via composer. If anyone would like more details, let me know.
Hi. would you please share how you solved it?
Sure. In
composer.json
, override ViewComponent.php
:
Copy the vendor ViewComponent.php
to your custom location. And change this part:
Then provide a custom blade for every component you use.
E.g. fieldset.blade.php
:
text-input.blade.php
:
textarea.blade.php
:
checkbox.blade.php
:
(I use this css for checkbox:)
Let me know if you need more explanation.
Oh, and you'll need something like this to generate the HTML. It has some stuff specific for my multi-form workflow, which you should change obviously:
This approach saves me SO much time vs manually building and keeping track of a PDF html next to the Filament definition.