How to generate a pdf in localstorage

Hi everyone, I’m doing a crud and Im practicing with jaspersoft to create reports from the database and is great I’m generating a pdf file that is always stored in the Project folder and I can use cmd start source and open it, the problem is when I’m checking the web app from a tablet to see if it is responsive and how it works, the pdf is not stored in the tablet, is stored in the computer where im coding, so the question is that, how can I do to store the pdf in the device that is running the app? I think that that is a client side thing but I’m not sure, so I really appreciate your help in this.

this is the button event:

Botones.reporte.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
try {
String nombrearchivo = "UsuariosRegistrados.pdf";

Class.forName("org.postgresql.Driver");
Connection dataSource = DriverManager.getConnection(dbUrl, dbUname, dbPwd);
dataSource.setAutoCommit(false);

InputStream ReporteUsuarios = getClass().getResourceAsStream("/ReporteUsuarios.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(ReporteUsuarios);
JRSaver.saveObject(jasperReport, "ReporteUsuarios.jasper");

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, dataSource);

JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(nombrearchivo));

SimplePdfReportConfiguration reportConfig = new SimplePdfReportConfiguration();
reportConfig.setSizePageToContent(true);
reportConfig.setForceLineBreakPolicy(false);

SimplePdfExporterConfiguration exportConfig = new SimplePdfExporterConfiguration();
exportConfig.setMetadataAuthor("Yeferson");
exportConfig.setEncrypted(true);
exportConfig.setAllowedPermissionsHint("PRINTING");

exporter.setConfiguration(reportConfig);
exporter.setConfiguration(exportConfig);

exporter.exportReport();
} catch (Exception e) {
System.out.println("Exceptiion" + e);
e.printStackTrace();
xMensaje = e.getMessage();
MessageBox.createError().withCaption("CRUD").withMessage("reporte no generado " + xMensaje).open();
}
}
});

You probably need to use the
FileDownloader extension
. You might also want to check the
report-

ui
component.

Thanks a Lot, that was veryhelpful, the problem was solved, I will check th FileDownloader extension and report-ui.

[code]
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.vaadin.ui.Button.ClickEvent;

import de.steinwedel.messagebox.MessageBox;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.util.JRSaver;
import net.sf.jasperreports.export.SimpleExporterInput;
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
import net.sf.jasperreports.export.SimplePdfExporterConfiguration;
import net.sf.jasperreports.export.SimplePdfReportConfiguration;

@SuppressWarnings({ "deprecation", "unused" })
@RestController
public class CrudReport {

    @Value("${spring.datasource.url}")
    String dbUrl;
    @Value("${spring.datasource.driver}")
    String dbDriver;
    @Value("${spring.datasource.username}")
    String dbUname;
    @Value("${spring.datasource.password}")
    String dbPwd; 
    @RequestMapping(value = "/pdfreporte", method = RequestMethod.GET,
            produces = MediaType.APPLICATION_PDF_VALUE)
            public ResponseEntity<InputStreamResource> usuariosReport() throws IOException {

            HttpHeaders headers = new HttpHeaders();
            headers.add("Content-Disposition", "inline; filename=reporte.pdf");
            ByteArrayInputStream bis = generaPdf();

            return ResponseEntity
                .ok()
                .headers(headers)
                .contentType(MediaType.APPLICATION_PDF)
                .body(new InputStreamResource(bis));
            }

    public  ByteArrayInputStream generaPdf() {
        try {
            Class.forName("org.postgresql.Driver");
            Connection dataSource = DriverManager.getConnection(dbUrl, dbUname, dbPwd);
            dataSource.setAutoCommit(false);
            InputStream ReporteUsuarios = getClass().getResourceAsStream("/Simple_Blue.jrxml");
            JasperReport jasperReport = JasperCompileManager.compileReport(ReporteUsuarios);
            JRSaver.saveObject(jasperReport, "Simple_Blue.jasper");
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, dataSource);
            JRPdfExporter exporter = new JRPdfExporter();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
            exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(out));

            exporter.exportReport();
            return new ByteArrayInputStream(out.toByteArray());
            
        } catch (Exception e) {
            System.out.println("Exceptiion" + e);
            e.printStackTrace();
            return null;
        }
    }
}
[/code]

Now Im trying to implement the FileDownload Method in a button.aaddClickListener() but I cant set the correct return type
How is te right way to set up the return type in this case?

btnExportarPais.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {

                StreamResource myResource = generaPdfPais();
                FileDownloader fileDownloader = new FileDownloader(myResource);
                fileDownloader.extend(btnExportarPais);
                setParent((HasComponents) btnExportarPais);
            }
            
            private ByteArrayInputStream generaPdfPais() {
                try {
                    Class.forName("org.postgresql.Driver");
                    Connection dataSource = DriverManager.getConnection(dbUrl, dbUname, dbPwd);
                    dataSource.setAutoCommit(false);
                    InputStream ReportePaises = getClass().getResourceAsStream("/ReportePaises.jrxml");
                    JasperReport jasperReport = JasperCompileManager.compileReport(ReportePaises);
                    JRSaver.saveObject(jasperReport, "ReportePaises.jasper");
                    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, dataSource);
                    JRPdfExporter exporter = new JRPdfExporter();
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
                    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(out));
                    exporter.exportReport();
                    return new ByteArrayInputStream(out.toByteArray());
                } catch (Exception e) {
                    System.out.println("Exceptiion" + e);
                    e.printStackTrace();
                    return null;
                }
            }
        });

I really appreciate your help in this, thanks in advance