示例#1
0
  public void SimpleReportDiretoPdf() {

    JasperPrint jp = null;
    try {

      JRDataSource customDs = new CustomBs();

      jp = JasperFillManager.fillReport(arq, null, customDs);

      JasperViewer jasperViewer = new JasperViewer(jp);

      jasperViewer.setBounds(50, 50, 320, 240);
      jasperViewer.setLocationRelativeTo(null);
      jasperViewer.setExtendedState(JFrame.MAXIMIZED_BOTH);

      jasperViewer.setVisible(true);

      JasperExportManager.exportReportToPdfFile(jp, OUT_PDF);

      JOptionPane.showMessageDialog(
          null,
          "<html>Arquivo exportado para PDF!<br><br>A aplicação vai pedir"
              + " ao Sistema operacional <br>para abrir com o visualizador"
              + " padrão.");

      Desktop.getDesktop().open(new File(OUT_PDF));

    } catch (JRException ex) {
      ex.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  public void executeReport() throws IOException {
    FacesContext facesContext = FacesContext.getCurrentInstance();

    HttpServletResponse response =
        (HttpServletResponse) facesContext.getExternalContext().getResponse();

    InputStream reportStream =
        facesContext.getExternalContext().getResourceAsStream("caminho_arquivo.jasper");

    response.setContentType("application/pdf");

    response.setHeader("Content-disposition", "inline;filename=relatorio.pdf");

    try {
      ServletOutputStream servletOutputStream = response.getOutputStream();

      JRBeanCollectionDataSource datasource = new JRBeanCollectionDataSource(arrayList);

      JasperRunManager.runReportToPdfStream(
          reportStream, servletOutputStream, parameters, datasource);

      servletOutputStream.flush();
      servletOutputStream.close();
    } catch (JRException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      facesContext.responseComplete();
    }
  }
  public void abrirRelatorio(ActionEvent evt) {
    try {
      String arquivo =
          "condominio/core/administrativo/relatorios/Blank_A4.jasper"; // arquivo de relatorio
      java.io.InputStream file =
          getClass().getClassLoader().getResourceAsStream(arquivo); // carrego o arquivo
      List<TIPO_MORADOR> allTipoMorador = pCrud.getAllTipoMorador();
      JRBeanArrayDataSource dataSource =
          new JRBeanArrayDataSource(
              allTipoMorador.toArray(
                  new TIPO_MORADOR
                      [allTipoMorador
                          .size()])); // aqui eu crio um datasource usando a propria jtable
      Map parametros =
          new HashMap(); // apenas crio um map, mas nem passo parametro nem nada, os parametros sao
      // as colunas da jtable
      JasperPrint printer = JasperFillManager.fillReport(file, parametros, dataSource);

      JRViewer view = new JRViewer(printer);

      view.setVisible(true);

      SwingNode panel = new SwingNode();
      panel.prefHeight(500);
      panel.prefWidth(500);
      panel.setContent(view);

      relat.getChildren().add(panel);

    } catch (JRException e) {
      e.printStackTrace();
    }
  }
示例#4
0
 public void print(boolean withPrintDialog) {
   try {
     JasperPrintManager.printReport(makeReport(), withPrintDialog);
   } catch (JRException e) {
     e.printStackTrace();
   }
 }
  public void imprimir(List<Produto> produtos) throws IOException {

    try {
      // Projeto do Relatorio feito no iReport ou outro programa
      // OBS: Para evitar erros, colocar o projeto do Relatorio no mesmo diretorio desta classe, ou
      // seja, ambos devem estar juntos.

      InputStream is = getClass().getResourceAsStream("RelVenda.jrxml");
      System.out.println(is);

      JasperReport report = JasperCompileManager.compileReport(is);

      // passar a lista recebida no método

      JasperPrint print =
          JasperFillManager.fillReport(
              report, null, new JRBeanCollectionDataSource(produtos, false));

      // Diretorio que deseja salvar o relatorio

      JasperExportManager.exportReportToPdfFile(print, "c:/RelatorioVendas.pdf");

      // Para abrir o relatorio na pasta que vc salvou, utilizar o comando abaixo

      Runtime.getRuntime().exec("cmd /c start C:/RelatorioVendas.pdf");

    } catch (JRException e) {
      e.printStackTrace();
    }
  }
  private void btnTodosActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnTodosActionPerformed
    try {
      // Arquivo do Relatorio
      // String relatorio = "/META-INF/relatorio/relatorioEstoque.jasper";
      InputStream relatorio =
          this.getClass()
              .getClassLoader()
              .getResourceAsStream("META-INF/relatorio/relatorioCompras.jasper");
      // Lista a ser exibida no relatorio
      CompraDAO compraDao = new CompraDAO();
      List<Compra> compras = new LinkedList<>();

      for (Compra c : compraDao.ListarTodos()) {
        c.setNomeFornecedor(c.getProduto().getFornecedor().getNome());
        compras.add(c);
      }

      // Fonte de dados
      JRBeanCollectionDataSource fonteDados = new JRBeanCollectionDataSource(compras);

      // Gera o Relatorio
      JasperPrint relatorioGerado = JasperFillManager.fillReport(relatorio, null, fonteDados);

      // Exibe o Relatorio
      JasperViewer jasperViewer = new JasperViewer(relatorioGerado, false);
      this.dispose();
      jasperViewer.setVisible(true);

    } catch (JRException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(this, e.getMessage());
    }
  } // GEN-LAST:event_btnTodosActionPerformed
 public static void main(String[] args) {
   try {
     compile("jasper_report_template.jrxml");
   } catch (JRException e) {
     e.printStackTrace();
   }
 }
示例#8
0
  @SuppressWarnings("unchecked")
  public static void main(String[] args) {
    try {
      URL url =
          JasperAB.class
              .getClassLoader()
              .getResource("br/com/analiseFornecedores/relatorio/relatorio_controle_1.jasper");
      File reportFile = new File(url.getFile());
      JasperReport relatorio = (JasperReport) JRLoader.loadObject(reportFile.getPath());
      Collection<RelatorioControleVO> lista = new ArrayList<RelatorioControleVO>();

      AnaliseRN rn = new AnaliseRN();
      Collection<AnaliseVO> analises = new ArrayList<AnaliseVO>();
      try {
        AnaliseVO filtro = new AnaliseVO();
        analises = rn.obterPorFiltro(filtro);
        lista = rn.obterRelatorioControle(analises);
      } catch (ExecaoRegraNegocio e) {
        e.printStackTrace();
      } catch (Exception e) {
        e.printStackTrace();
      }

      JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(lista);
      Map<?, ?> param = new HashMap();
      JasperPrint jasperPrint = JRFiller.fillReport(relatorio, param, ds);
      JasperViewer.viewReport(jasperPrint, true);
    } catch (JRException e) {
      e.printStackTrace();
    }
  }
示例#9
0
 protected void onGenerarInformeButtonActionPerformed(ActionEvent e) {
   // crear informe pasandole los datos en el constructor
   try {
     new Informe(this);
   } catch (JRException e1) {
     e1.printStackTrace();
   }
 }
 @Override
 public void execute() {
   super.execute();
   try {
     if (var != null) jDataset.addVariable((JRDesignVariable) var);
   } catch (JRException e) {
     e.printStackTrace();
   }
 }
示例#11
0
 private void close() {
   JRTableModelDataSource ds = new JRTableModelDataSource(m_model);
   try {
     m_jasperPrint = JasperFillManager.fillReport(m_jasperReport, m_parameters, ds);
   } catch (JRException e) {
     e.printStackTrace();
   }
   m_jrv = new JRViewer(m_jasperPrint);
 }
  @SuppressWarnings({"rawtypes", "unchecked"})
  protected void procesar(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // TODO Auto-generated method stub

    /*CABECERA DE SALIDA*/
    response.setHeader("Content-Disposition", "attachment; filename=\"CronogramaCredito.pdf\";");
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("application/pdf");

    /*OBTIENE FLUJO DE SALIDA*/
    ServletOutputStream outputStream = response.getOutputStream();

    /*PARAMETROS*/
    Parameters parameters = Parameters.getInstance();

    /*SERVICIO DE GENERACION DE REPORTES*/
    ReporteJasperServiceImpl jasperServiceImpl = new ReporteJasperServiceImpl();

    /*RECUPERA DATOS DE LA SIMULACION EN SESION*/
    HttpSession session = request.getSession(true);
    CreditoCabeceraBO creditoCabeceraBO =
        (CreditoCabeceraBO) session.getAttribute("creditoCabeceraBO");
    CreditoCronogramaBO creditoCronogramaBO =
        (CreditoCronogramaBO) session.getAttribute("creditoCronogramaBO");
    List<Cuota> listaCuotasCredito = (List<Cuota>) session.getAttribute("listaCuotasCredito");

    try {
      /* CARGA PARAMETROS PARA REPORTE JASPER*/
      JasperReport reporte =
          (JasperReport)
              JRLoader.loadObject(
                  this.getClass()
                      .getClassLoader()
                      .getResourceAsStream(parameters.getKey("REPORTE_CREDITO_PYME")));

      /* CARGA PARAMETROS DEL REPORTE*/
      Map paramReporte =
          jasperServiceImpl.getParamReporCredPYME(creditoCabeceraBO, creditoCronogramaBO);

      /* GENERA REPORTE*/
      JRExporter exporterPDF =
          jasperServiceImpl.getExporterJasper(
              reporte, paramReporte, new JRBeanCollectionDataSource(listaCuotasCredito));
      exporterPDF.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);

      /*MUESTRA REPORTE EN LINEA*/
      exporterPDF.exportReport();

    } catch (JRException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
 public static void compile(final String sourceFileName) throws JRException {
   System.out.println("Compiling Report Design ...");
   try {
     JasperCompileManager.compileReportToFile(sourceFileName);
   } catch (JRException e) {
     e.printStackTrace();
     throw e;
   }
   System.out.println("Done compiling!!! ...");
 }
  private JRRenderable getRenderer() {
    JRRenderable imageRenderer = null;
    Image awtImage = null;

    try {
      awtImage = JRImageLoader.getImage(JRImageLoader.SUBREPORT_IMAGE);
      imageRenderer = JRImageRenderer.getInstance(awtImage, JRImage.ON_ERROR_TYPE_ERROR);
    } catch (JRException e) {
      e.printStackTrace(); // FIXMECONVERT use logging
    }

    return imageRenderer;
  }
示例#15
0
 public String exporterPDF() {
   if (codeevaluation != 0) {
     try {
       this.service.imprimerNotesClasse(codeevaluation);
     } catch (IOException e) {
       Repertoire.addMessageerreur("Une erreur est survenue lors de l'impresson", e);
       e.printStackTrace();
     } catch (JRException e) {
       Repertoire.addMessageerreur("Une erreur est survenue lors de l'impresson", e);
       e.printStackTrace();
     }
   }
   return null;
 }
示例#16
0
 public void viewJasper(String path, String name, String outPath, List<?> list) {
   name = parseJrXml(path, name);
   HashMap<String, Object> hm = new HashMap<String, Object>();
   JasperPrint print;
   try {
     print =
         JasperFillManager.fillReport(outPath + name, hm, new JRBeanCollectionDataSource(list));
     JasperViewer jrview = new JasperViewer(print, false);
     jrview.setPreferredSize(new Dimension(200, 100));
     jrview.setVisible(true);
   } catch (JRException e) {
     e.printStackTrace();
   }
 }
示例#17
0
 private String parseJrXml(String path, String name) {
   // 如果是.jrxml手工编译
   if (name.contains(".jrxml")) {
     try {
       // 在当前目录编译
       JasperCompileManager.compileReportToFile(path + name);
       name = name.replace(".jrxml", ".jasper");
     } catch (JRException e1) {
       e1.printStackTrace();
     }
   }
   System.out.println(name);
   return name;
 }
  private void btnFornecedorActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnFornecedorActionPerformed

    try {
      // Pegando o id do Produto

      String fornecedor = JOptionPane.showInputDialog("Insira o Id do Fornecedor");

      // Arquivo do Relatorio
      // String relatorio = "/META-INF/relatorio/relatorioEstoque.jasper";
      InputStream relatorio =
          this.getClass()
              .getClassLoader()
              .getResourceAsStream("META-INF/relatorio/relatorioCompras.jasper");
      // Lista a ser exibida no relatorio

      CompraDAO comprasDAO = new CompraDAO();

      List<Compra> compras = comprasDAO.ListarTodos();
      List<Compra> comprasFiltro = new LinkedList<>();
      for (Compra c : compras) {
        if (c.getProduto().getFornecedor().getId() == Long.parseLong(fornecedor)) {
          comprasFiltro.add(c);
        }
      }

      if (!comprasFiltro.isEmpty()) {

        // Fonte de dados
        JRBeanCollectionDataSource fonteDados = new JRBeanCollectionDataSource(comprasFiltro);

        // Gera o Relatorio
        JasperPrint relatorioGerado = JasperFillManager.fillReport(relatorio, null, fonteDados);

        // Exibe o Relatorio
        JasperViewer jasperViewer = new JasperViewer(relatorioGerado, false);
        this.dispose();
        jasperViewer.setVisible(true);
      } else {
        JOptionPane.showMessageDialog(rootPane, "Fornecedor não encontrado !");
      }

    } catch (JRException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(this, e.getMessage());
    } catch (NumberFormatException e) {
      JOptionPane.showMessageDialog(rootPane, "Id inválido !");
    }
  } // GEN-LAST:event_btnFornecedorActionPerformed
  /**
   * @param contexto
   * @param directorioReporte
   * @param nombreReporte
   * @return
   * @throws JRException
   */
  public boolean compilaReporte(
      ExternalContext contexto, String directorioReporte, String nombreReporte) throws JRException {
    String reporteJasper = contexto.getRealPath(directorioReporte + nombreReporte + ".jasper");
    File archivoJasper = new File(reporteJasper);

    if (archivoJasper.exists()) {
      return true;
    }
    try {
      compila(contexto, directorioReporte);
      String archivoJRXML = reporteJasper.substring(0, reporteJasper.indexOf(".jasper")) + ".jrxml";
      JasperCompileManager.compileReportToFile(archivoJRXML);
      return true;
    } catch (JRException e) {
      e.printStackTrace();
      return false;
    }
  }
示例#20
0
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    ClassPathXmlApplicationContext context =
        new ClassPathXmlApplicationContext("classpath:/META-INF/spring/applicationContext.xml");

    DataSource dataSource = (DataSource) context.getBean("dataSource");
    Connection conn = null;
    Map<String, Object> parametros = new HashMap<String, Object>();

    try {
      parametros.put("id", Long.parseLong(request.getParameter("id")));
      System.out.println(
          getServletContext().getRealPath("") + " Hello World " + request.getParameter("id"));
      conn = dataSource.getConnection();

      File reportFile = new File(getServletContext().getRealPath("") + "/META-INF/report.jasper");

      JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportFile);

      // this.preencherRelatorio(request);

      JasperPrint jasperPrint = null;

      response.setContentType("application/pdf");
      jasperPrint = JasperFillManager.fillReport(jasperReport, parametros, conn);

      System.out.println(jasperPrint);

      JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
    } catch (JRException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  @Override
  public void test() {
    super.test();

    numberOfPagesTest(1);

    try {
      byte[] imageData =
          JRImageLoader.getInstance(DefaultJasperReportsContext.getInstance())
              .loadBytesFromAwtImage(image, ImageTypeEnum.JPEG);
      JRPrintImage jrImage = (JRPrintImage) getElementAt("title.image1", 0);
      Assert.assertTrue(
          "image data",
          Arrays.equals(
              imageData,
              jrImage.getRenderable().getImageData(DefaultJasperReportsContext.getInstance())));
      Assert.assertEquals("scale image", ScaleImageEnum.CLIP, jrImage.getScaleImageValue());
    } catch (JRException e) {
      e.printStackTrace();
      Assert.fail(e.getMessage());
    }
  }
示例#22
0
  /** Performs the decompilation of the selected report design files. */
  protected void decompile() throws BuildException {
    Collection<String> files = reportFilesMap.keySet();

    if (files != null && files.size() > 0) {
      boolean isError = false;

      System.out.println("Decompiling " + files.size() + " report design files.");

      for (Iterator<String> it = files.iterator(); it.hasNext(); ) {
        String srcFileName = it.next();
        String destFileName = reportFilesMap.get(srcFileName);
        File destFileParent = new File(destFileName).getParentFile();
        if (!destFileParent.exists()) {
          destFileParent.mkdirs();
        }

        try {
          System.out.print("File : " + srcFileName + " ... ");

          JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile(srcFileName);

          new JRXmlWriter(jasperReportsContext).write(jasperReport, destFileName, "UTF-8");

          System.out.println("OK.");
        } catch (JRException e) {
          System.out.println("FAILED.");
          System.out.println("Error decompiling report design : " + srcFileName);
          e.printStackTrace(System.out);
          isError = true;
        }
      }

      if (isError) {
        throw new BuildException("Errors were encountered when decompiling report designs.");
      }
    }
  }
  private void btnGerarActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnGerarActionPerformed
    try {
      String relatorio = System.getProperty("user.dir") + "/relatorios/consultaPaciente.jasper";

      ConsultaBO consultaBO = new ConsultaBO();
      // Criar a fonte de dados do JasperReport
      JRBeanCollectionDataSource fontedados =
          new JRBeanCollectionDataSource(
              consultaBO.buscarTodosPorPaciente((Paciente) cmbPaciente.getSelectedItem()));

      // Gerar o relatorio
      JasperPrint relatorioGerado = JasperFillManager.fillReport(relatorio, null, fontedados);

      // Exibir Relatorio
      JasperViewer jasperViewer = new JasperViewer(relatorioGerado, false);
      jasperViewer.setVisible(true);

    } catch (JRException ex) {
      ex.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  } // GEN-LAST:event_btnGerarActionPerformed
  @Override
  public JRDesignElement createReportElement(JasperDesign jd) {
    JRDesignTextField element = (JRDesignTextField) super.createReportElement(jd);

    FieldPercentageDialog dialog = new FieldPercentageDialog(Misc.getMainFrame());
    dialog.setJasperDesign(jd);

    dialog.setVisible(true);
    if (dialog.getDialogResult() == JOptionPane.OK_OPTION) {
      JRField f = dialog.getSelectedField();
      ResetTypeEnum resetType = dialog.getSelectedResetTypeValue();
      JRGroup group = null;
      if (resetType == ResetTypeEnum.GROUP) {
        group = dialog.getSelectedGroup();
      }

      // Let's create the variable...

      JRDesignVariable variable = new JRDesignVariable();
      for (int i = 0; ; ++i) {
        String vname = f.getName() + "_SUM";
        if (i > 0) vname += "_" + i;

        if (jd.getVariablesMap().containsKey(vname)) {
          continue;
        }

        variable.setName(vname);
        break;
      }

      variable.setExpression(
          Misc.createExpression(f.getValueClassName(), "$F{" + f.getName() + "}"));
      variable.setValueClassName(f.getValueClassName());
      variable.setCalculation(CalculationEnum.SUM);
      variable.setResetType(resetType);
      if (resetType == ResetTypeEnum.GROUP) {
        variable.setResetGroup(group);
      }
      try {
        jd.addVariable(variable);
      } catch (JRException ex) {
        ex.printStackTrace();
      }

      ((JRDesignExpression) element.getExpression())
          .setText(
              "new Double( $F{"
                  + f.getName()
                  + "}.doubleValue() / $V{"
                  + variable.getName()
                  + "}.doubleValue() )");
      ((JRDesignExpression) element.getExpression()).setValueClassName("java.lang.Double");

      element.setPattern("#,##0.00%");
      setMatchingClassExpression(
          ((JRDesignExpression) element.getExpression()),
          ((JRDesignExpression) element.getExpression()).getValueClassName(),
          true);

      element.setEvaluationTime(EvaluationTimeEnum.AUTO);

      return element;
    }

    return null;
  }
示例#25
0
  protected void createReport2(HttpServletRequest req, HttpServletResponse resp, String strNoSTS)
      throws ServletException, IOException {
    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      String strDSN = jvCommonClass.fnGetProperty("DSN");
      java.sql.Connection con = DriverManager.getConnection("jdbc:odbc:" + strDSN);
      String strFileJRXML = "report5.jrxml";
      String strFileJasper =
          (new StringBuilder(String.valueOf(JRXML_LOCAL_PATH))).append(strFileJRXML).toString();
      String strTglAnggaran = req.getSession().getAttribute("strTglAnggaran").toString();
      Date dtTglAnggaran = null;
      try {
        dtTglAnggaran = (new SimpleDateFormat("dd/MM/yyyy")).parse(strTglAnggaran);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      String strNamaPemda = req.getParameter("hidNamaPemda").toString();
      String strNamaBidang = req.getParameter("hidNamaBidang").toString();
      String strAlamatPemda = req.getParameter("hidAlamatPemda").toString();
      String strKotamadyaPemda = req.getParameter("hidKotamadyaPemda").toString();
      String strKodePos = req.getParameter("hidKodePos").toString();
      String strTelepon = req.getParameter("hidTelepon").toString();
      String strFacsimile = req.getParameter("hidFacsimile").toString();
      String strNamaUser = req.getParameter("hidNamaUser").toString();
      String strKdJabatanUser = req.getParameter("hidKdJabatanUser").toString();
      String strNIPUser = req.getParameter("hidNIPUser").toString();
      String strJabatanUser = req.getParameter("hidJabatanUser").toString();
      String strAngka = req.getParameter("hidTotal").toString();
      String strTerbilang = req.getParameter("hidTerbilang").toString();
      String strNamaPejabat = req.getParameter("hidNamaPejabat").toString();
      String strJabatanPejabat = req.getParameter("hidJabatanPejabat").toString();
      String strNIPPejabat = req.getParameter("hidNIPPejabat").toString();
      Map parameters = new HashMap();
      parameters.put("pNamaPemda", strNamaPemda);
      parameters.put("pNamaDinas", strNamaBidang);
      parameters.put("pNoSTS", strNoSTS);
      parameters.put("pAngka", strAngka);
      parameters.put("pTerbilang", strTerbilang);
      parameters.put("pNamaAtasan", strNamaPejabat);
      parameters.put("pJabatanAtasan", strJabatanPejabat);
      parameters.put("pNIP", strNIPPejabat);
      String strNamaBendahara = "";
      String strNIPBendahara = "";
      Hashtable htInfoPejabat1 = jvg.fnGetInfoPejabat();
      int intHtInfoPejabat = htInfoPejabat1.size();
      for (int a = 1; a <= intHtInfoPejabat; a++) {
        String strArray[] = (String[]) htInfoPejabat1.get(String.valueOf(a));
        if (strArray[0].equals("31100")) {
          strNamaBendahara = strArray[1];
          strNIPBendahara = strArray[2];
        }
      }

      parameters.put("pNamaBendahara", strNamaBendahara);
      parameters.put("pNIPBendahara", strNIPBendahara);
      SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");
      Date todayDate = new Date();
      String strToday = sdf.format(todayDate);
      net.sf.jasperreports.engine.JasperReport jasperReport =
          JasperCompileManager.compileReport(strFileJasper);
      net.sf.jasperreports.engine.JasperPrint print =
          JasperFillManager.fillReport(jasperReport, parameters, con);
      String strFilePDF = (new StringBuilder("STS_")).append(strToday).append(".pdf").toString();
      String strOutput =
          (new StringBuilder(String.valueOf(REPORT_LOCAL_PATH))).append(strFilePDF).toString();
      JasperExportManager.exportReportToPdfFile(print, strOutput);
      String strPDFOutput =
          (new StringBuilder(String.valueOf(OUTPUT_LOCAL_PATH))).append(strFilePDF).toString();
      resp.sendRedirect(strPDFOutput);
    } catch (ClassNotFoundException cnfe) {
      cnfe.printStackTrace();
    } catch (SQLException sqle) {
      sqle.printStackTrace();
    } catch (JRException jre) {
      jre.printStackTrace();
    }
  }
  public void printGR() {
    LogManager log = new LogManager();
    try {
      JasperReport report = null;
      report =
          (JasperReport)
              JRLoader.loadObject(this.getClass().getResource("/welfare/reports/grForm.jasper"));
      // report = (JasperReport)JRLoader.loadObject("D:/grForm.jasper");

      ArrayList<PurchasingGRReportData> grReportList = new ArrayList<PurchasingGRReportData>();

      for (GoodsReceiptItem goodsReceiptItem : grItemList) {
        PurchasingGRReportData grReport = new PurchasingGRReportData();

        grReport.setItemNo(goodsReceiptItem.getItemNumber());
        grReport.setOrderQty(goodsReceiptItem.getOrderQty());
        grReport.setReceivedQty(goodsReceiptItem.getReceivedQty());
        grReport.setUnit(goodsReceiptItem.getReceiveUnit());
        grReport.setUnitPrice(goodsReceiptItem.getUnitPrice());

        String material = "";
        if (goodsReceiptItem.getMaterial() == null) {
          material = goodsReceiptItem.getOtherMaterial();
        } else {
          material = goodsReceiptItem.getMaterial().getDescription();
        }
        grReport.setMaterial(material);
        grReportList.add(grReport);
      }

      vendor = poController.getVendorForReport(editGR.getPurchaseOrder().getId());
      String text = "";
      if (editGR.getStatus().toString().equals("GR-FULL")) {
        text = "ÃѺàµçÁ¨Ó¹Ç¹";
      }
      if (editGR.getStatus().toString().equals("GR-PAR")) {
        text = "ÃѺäÁèàµçÁ¨Ó¹Ç¹";
      }

      HashMap grReportHashMap = new HashMap();
      grReportHashMap.put("grNo", editGR.getFormattedGrNumber());
      grReportHashMap.put("receivedDate", editGR.getReceivedDate());
      grReportHashMap.put("poNo", editGR.getPurchaseOrder().getFormattedPoNumber());
      grReportHashMap.put("status", editGR.getStatus().toString());
      grReportHashMap.put("invoiceNo", editGR.getInvoiceNumber());
      if (vendor != null) {
        grReportHashMap.put("vendor", vendor.getName());
      } else {
        grReportHashMap.put("vendor", editGR.getPurchaseOrder().getOtherVendor());
      }
      grReportHashMap.put("text", text);
      grReportHashMap.put("recipientName", editGR.getRecipientName());
      grReportHashMap.put("entryName", editGR.getEntryName());
      grReportHashMap.put("recipientPos", editGR.getRecipientPos());
      grReportHashMap.put("entryPos", editGR.getEntryPos());
      grReportHashMap.put("totalPrice", editGR.getTotalPrice());
      grReportHashMap.put("totalDiscount", editGR.getTotalDiscountAmount());
      grReportHashMap.put("LOGO", this.getClass().getResource("/welfare/reports/logo.gif"));
      grReportHashMap.put("logo", this.getClass().getResource("/welfare/reports/aerologo.png"));

      JasperPrint jasperPrint =
          JasperFillManager.fillReport(
              report, grReportHashMap, new JRBeanCollectionDataSource(grReportList));

      // JasperExportManager.exportReportToPdfFile(jasperPrint,"D:/testGR.pdf");
      byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint);
      ReportUtils.displayPdfReport(bytes);
      log.recordPrintGr(editGR.getFormattedGrNumber());

    } catch (JRException e) {
      // TODO: handle exception
      e.printStackTrace();
      e.getMessage();
    } catch (ControllerException e) {
      FacesUtils.reportError(FacesContext.getCurrentInstance(), e.getMessage(), e.getMessage(), e);
      e.printStackTrace();
    } catch (IOException e) {
      // TODO: handle exception
      e.printStackTrace();
    }
  }