Generate a pdf from BulkAction values
Hello, how can y build the same document from BulkAction values with an intermediate form to set some other properties?
20 Replies
Sorry what do you mean?
I need to do this but with BulkAction.
Since ->url and ->openUrlInNewTab() are not possible with BulkAction, what can I do to call the view with the selected records?
I would truly re-think this approach. Bulk actions run on every record selected. So it the user selected 50 items and ran your bulk action it would open 50 tabs and bog down your server trying to generate 50 pdfs at the same time.
That's probably what I have to do, but how can I generate one pdf with the 50 items? Is there another way to select them?
Could probably do a custom bulk action and use the items to generate one pdf. Then you could redirect() to the url. But there’s not a good way to open it in a new tab from the backend. You can emit a browser event and use a Js listener to open a url, but it has some caveats. https://developer.mozilla.org/en-US/docs/Web/API/Window/open
Window: open() method - Web APIs | MDN
The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.
Thank you, I'm gonna try to generate the pdf first.
Generate the pdf then download:
Hello, this is kinda working, the problem for me is that it asks where to save the file, what can I change to show the pdf instead of download?
Resource
Controller
I don't think that's possible. In a normal action, you could use
->url()
and then redirect to your controller. But BulkActions don't have the url()
method which makes sense because you'd open a bunch of URLs. Might be another way, but not that I'm aware of. SorryThanks for your help.
Maybe you could send it to a job, then when that’s done send a notification with the link in the body of the notification. And set the notification to be persistent so it doesn’t disappear. Then the user can keep working until it’s done and open it when it’s ready.
oooooooo...I like it!
Fair amount of moving parts, but might be the best bet for this use case. Imagine the server crashing because some selected 100s of records.
agree
Or worse, someone sitting on a loading spinner for 15 minutes. Lol.
I actually ended up putting my PDF generator as a function within the Model and just call it that way and provide a path for it, looping through the records and add them to a zip and stream it to download.
I believe that’s similar to what I had suggested at first, but OP wants to be able to view the generated PDF, not download it.
Ahh, from a bulk action just open in a new tab?
Url() doesn’t exist in bulk actions, which makes sense since it’d open a bunch of urls. That’s why Adam suggested that round about way to present a Url in a notification. Maybe we’re overlooking something?
->url() doesn't but you can trigger a url response if memory serves me right but I could be wrong