Print with vaadin

I need to print one jasperreport,
Today I use this code:

try {
            Resource resource = resourceLoader.getResource(resourceLoader.CLASSPATH_URL_PREFIX + "/static/relatorios/ReciboMovimentacaoMultiPedidos.jrxml");
            JasperDesign jasperDesign = JRXmlLoader.load(resource.getInputStream());
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
            Map<String,Object> parametros = new HashMap<>();
            StreamResource.StreamSource source = new StreamResource.StreamSource() {
                public InputStream getStream() {
                    byte[] b = null;
                       b = JasperRunManager.runReportToPdf(jasperReport,parametros, jdbcTemplate.getDataSource().getConnection());
                    } catch (Exception e) {
                    return new ByteArrayInputStream(b);

        StreamResource resourcesReport = new StreamResource(source, "ServicosPorPeriodo" + System.currentTimeMillis() + ".pdf");
        BrowserWindowOpener opener = new BrowserWindowOpener(resourcesReport);

        Button downloadButton = new Button(FontAwesome.DOWNLOAD);

        panelDownload.setComponentAlignment(downloadButton, Alignment.MIDDLE_RIGHT);

        }catch (Exception e){

But I dont want to show another button to my user click in this button to open a new window, and then click the print button

I want to send to print after finish to generate te rel.

it`s possible?? how??



The first link only show how to print a PDF opening a window(just like my sample) I need to send direclty to and not make my user click in a button.

and 2 link dont work.


The second link works for me.
You need to call the following code on the ui / view where you display your result. JavaScript.getCurrent().execute("print();");

Nice. but how I open the window without obrigate my user to click in button



Using javascript print() function works well for a web-html page. If your pdf is simple enough, it could be easier to achieve it this way : you render html page adding a post-loading print() then close() function (purely js inside HTML page).
If you really need pdf file, you are hard-linked to the viewer. Acrobat plugin will not react the same as internal browser viewer will do… May be you can control all the steps using pdfjs addon (!addon/pdfviewer )


In case someone needs it, I implemented a demo that shows how to automatically open the browser’s “print dialog” for a PDF file: