title: Automatically open the printer dialog after providing PDF download
body: <p>I am currently opening a pdf file in a new tab in my browser but I need to know how to open a printer dialog to print the pdf jasper report after pressing a commandButton</p>
  
  <p><strong>This is the method that open the pdf in a new tab:</strong></p>
  
  <pre><code>public void printJasper() {
  
      JasperReport compiledTemplate = null;
      JRExporter exporter = null;
      ByteArrayOutputStream out = null;
      ByteArrayInputStream input = null;
      BufferedOutputStream output = null;
  
      FacesContext facesContext = FacesContext.getCurrentInstance();
      ExternalContext externalContext = facesContext.getExternalContext();
      HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
  
      try {
  
          List&lt;String&gt; sampleList = new ArrayList&lt;String&gt;();
          sampleList.add("Fist sample string");
          sampleList.add("Second sample string");
  
          JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(sampleList);
          Map&lt;String, Object&gt; reportValues = new HashMap&lt;String, Object&gt;();
          reportValues.put("anyTestValue", "test value");
  
          facesContext = FacesContext.getCurrentInstance();
          externalContext = facesContext.getExternalContext();
          response = (HttpServletResponse) externalContext.getResponse();
  
          FileInputStream file = new FileInputStream("/any_dir/sample.jasper");
          compiledTemplate = (JasperReport) JRLoader.loadObject(file);
  
          out = new ByteArrayOutputStream();
          JasperPrint jasperPrint = JasperFillManager.fillReport(compiledTemplate, reportValues, beanCollectionDataSource);
  
          exporter = new JRPdfExporter();
          exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
          exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
          exporter.exportReport();
  
          input = new ByteArrayInputStream(out.toByteArray());
  
          response.reset();
          response.setHeader("Content-Type", "application/pdf");
          response.setHeader("Content-Length", String.valueOf(out.toByteArray().length));
          response.setHeader("Content-Disposition", "inline; filename=\"fileName.pdf\"");
          output = new BufferedOutputStream(response.getOutputStream(), Constants.DEFAULT_BUFFER_SIZE);
  
          byte[] buffer = new byte[Constants.DEFAULT_BUFFER_SIZE];
          int length;
          while ((length = input.read(buffer)) &gt; 0) {
              output.write(buffer, 0, length);
          }
          output.flush();
  
      } catch (Exception exception) {
          /* ... */
      } finally {
          try {
              if (output != null) {
                  output.close();
              }
              if (input != null) {
                  input.close();
              }
          } catch (Exception exception) {
              /* ... */
          }
      }
      facesContext.responseComplete();
  }
  </code></pre>
  
  <p><strong>This is the button that open the pdf file:</strong></p>
  
  <pre><code>&lt;p:commandButton action="#{sampleBB.printJasper}"
      ajax="false" onclick="this.form.target='_blank'"
      value="#{msg['generate.report']}" /&gt;
  </code></pre>
  
  <p>What I need to do?</p>