예제 #1
0
 public void generateHtmlReport(JasperPrint jasperPrint, String htmlFile) {
   JRHtmlExporter exporter = new JRHtmlExporter();
   try {
     exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
     exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, htmlFile);
     exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image=");
     exporter.exportReport();
   } catch (JRException jrEx) {
     LOG.error(ERROR_GENERATING + jasperPrint.getName(), jrEx);
   }
 }
예제 #2
0
 public static void createHTMLReport(
     InputStream reportFile, GridReportVO gridReportVO, String path, String fileName)
     throws JRException, IOException {
   gridReportVO.setPagination(false);
   JasperPrint jasperPrint = createJasperPrint(reportFile, gridReportVO);
   JRHtmlExporter exporter = new JRHtmlExporter();
   Map<JRExporterParameter, Object> p = new HashMap<JRExporterParameter, Object>();
   p.put(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
   p.put(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
   p.put(JRHtmlExporterParameter.OUTPUT_FILE_NAME, path + "/" + fileName);
   exporter.setParameters(p);
   exporter.exportReport();
 }
예제 #3
0
  public static void exportReportHtml(JasperPrint jp, String path)
      throws JRException, FileNotFoundException {
    JRHtmlExporter exporter = new JRHtmlExporter();

    File outputFile = new File(path);
    File parentFile = outputFile.getParentFile();
    if (parentFile != null) {
      parentFile.mkdirs();
    }
    FileOutputStream fos = new FileOutputStream(outputFile);

    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos);
    exporter.exportReport();

    logger.debug("HTML Report exported: " + path);
  }
  public void save(JasperPrint jasperPrint, File file) throws JRException {
    if (!file.getName().toLowerCase().endsWith(EXTENSION_HTM)
        && !file.getName().toLowerCase().endsWith(EXTENSION_HTML)) {
      file = new File(file.getAbsolutePath() + EXTENSION_HTML);
    }

    if (!file.exists()
        || JOptionPane.OK_OPTION
            == JOptionPane.showConfirmDialog(
                null,
                MessageFormat.format(getBundleString("file.exists"), new Object[] {file.getName()}),
                getBundleString("save"),
                JOptionPane.OK_CANCEL_OPTION)) {
      JRHtmlExporter exporter = new JRHtmlExporter();
      exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
      exporter.setParameter(JRExporterParameter.OUTPUT_FILE, file);
      exporter.exportReport();
    }
  }
예제 #5
0
  /** 导出html */
  private static void exportHtml(
      JasperPrint jasperPrint,
      String defaultFilename,
      HttpServletRequest request,
      HttpServletResponse response)
      throws IOException, JRException {
    response.setContentType("text/html");
    ServletOutputStream ouputStream = response.getOutputStream();
    JRHtmlExporter exporter = new JRHtmlExporter();
    exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);

    exporter.exportReport();

    ouputStream.flush();
    ouputStream.close();
  }
예제 #6
0
  protected void generateHtmlOutput(
      JasperPrint jasperPrint, HttpServletResponse resp, HttpServletRequest request)
      throws IOException, JRException {

    // resp.setContentType("text/html");
    // PrintWriter out = resp.getWriter();
    // JRExporter exporter = new JRHtmlExporter();
    // // Map imagesMap = new HashMap();
    // // request.getSession().setAttribute("IMAGES_MAP", imagesMap);
    // exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    // exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
    // //
    // exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,
    // // Boolean.FALSE);
    // exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,
    // "../images/pximages/");
    // exporter.exportReport();
    // out.flush();
    // out.close();
    // clear();

    File imageFile = new File("");
    System.out.println("images path :" + imageFile.getAbsolutePath());
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();
    // String pathName = request.getRealPath("report/" + "reportHtml"
    // + ".html");
    // String i =
    // "http://"+request.getLocalAddr()+":"+Integer.toString(request.getLocalPort())+request.getContextPath()+"\\LHBUWeb\\WebContent\\fixedreport\\internal.jpg";
    // String i =
    // "http://"+request.getLocalAddr()+":"+Integer.toString(request.getLocalPort())+request.getContextPath()+"\\images\\internal.jpg";
    StringBuffer sbHeader = new StringBuffer();
    sbHeader
        .append("<head>")
        .append("<title></title>")
        .append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>")
        .append("<style type=\"text/css\">")
        // .append("table {").append("background-image:
        // url(").append(url).append(");").append("}")

        // .append("table {").append("background-image:
        // url(file://").append(i).append(");").append("}")
        .append("\n body { margin:50px 0px; padding:0px; text-align:center; } ")
        .append("table {")
        .append("background-image: url(..")
        .append("../img/refresh.png")
        .append(");")
        .append("\nbackground-repeat: no-repeat;")
        .append("\nbackground-position:center;")
        .append("\nmargin-left : auto;")
        .append("margin-right : auto;")
        .append("}")
        // ok .append("table {").append("background-image:
        // url(../fixedreport/internal.jpg").append(");").append("}")
        // .append("table {").append("background-image:
        // url(file:///").append(url).append(");").append("}")

        // file:///
        .append("</style>")
        .append("</head>");
    // String a = request.getContextPath();
    // String b = request.getPathInfo();
    // String c = request.getProtocol();
    // String d = request.getLocalAddr();
    // String e = request.getRequestURL().toString();
    // String f = Integer.toString(request.getLocalPort());
    // System.out.println(sbHeader.toString());

    /*
     * <head> <title></title> <meta http-equiv="Content-Type"
     * content="text/html; charset=UTF-8"/> <style type="text/css"> table {
     * background-image:
     * url(../../../../Project%20LHBU/Support/watermark.jpg); } </style>
     * </head>
     */

    JRHtmlExporter exporter = new JRHtmlExporter();
    // JasperExportManager.exportReportToHtmlFile(jasperPrint, pathName);
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    // exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,pathName);
    // if (!isChart)
    exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
    // if (isChart)
    // {

    // exporter.setParameter(JRHtmlExporterParameter.OUTPUT_STRING_BUFFER,new
    // StringBuffer());
    // exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,"../images/pximages/");
    exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, sbHeader.toString());
    exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, IMAGE_PATH);

    exporter.exportReport();
    out.flush();
    out.close();
  }