Download a generate file with I click on a Button

Hello.

I want when I click on a Button generate a PDF or Excel file and immediately download this file.

What is good practice?

THANKS

Download a generate file with I click on a Button

Here’s an example using an addon from @vital-koala How do I download text area contents as a file - Vaadin Cookbook

And If you don’t want to keep the file in the server memory, use this newer approach to dynamically write the content of

setHref(new StreamResource("screenshot.png", (outputstream, session) -> {    outputstream.write("Hello".getBytes());}));```

Or go with Viritin add-on and its DynamicFileDownload component:

https://github.com/viritin/flow-viritin/blob/v24/src/test/java/org/vaadin/firitin/DynamicFileDownloadingDemo.java