Esempio n. 1
0
 /**
  * 用jasperReport导出Pdf
  *
  * @param request
  * @param response
  * @param reportFilePath jasper报表文件路径
  * @param paramMap 字段
  * @param dataList
  * @throws IOException
  * @throws JRException void
  * @author xiaobao @Create Mar 5, 2012 10:01:39 AM
  */
 public static String exportReportToPDF(
     HttpServletRequest request,
     HttpServletResponse response,
     String reportFilePath,
     Map<String, Object> paramMap,
     List dataList)
     throws IOException, JRException {
   JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(dataList);
   String fileName = paramMap.get("fileName").toString();
   fileName = fileName + ".pdf";
   String path =
       request.getRealPath("/")
           + File.separator
           + "report"
           + File.separator
           + "export"
           + File.separator
           + fileName;
   JasperRunManager.runReportToPdfFile(reportFilePath, path, paramMap, dataSource);
   return fileName;
 }
  public void run() throws JRException {
    long start = System.currentTimeMillis();
    // Preparing parameters
    Image image = Toolkit.getDefaultToolkit().createImage("dukesign.jpg");
    MediaTracker traker = new MediaTracker(new Panel());
    traker.addImage(image, 0);
    try {
      traker.waitForID(0);
    } catch (Exception e) {
      e.printStackTrace();
    }

    Map parameters = new HashMap();
    parameters.put("ReportTitle", "The First Jasper Report Ever");
    parameters.put("MaxOrderID", new Integer(10500));
    parameters.put("SummaryImage", image);

    JasperRunManager.runReportToPdfFile(
        "build/reports/FirstJasper.jasper", parameters, getDemoHsqldbConnection());
    System.err.println("PDF running time : " + (System.currentTimeMillis() - start));
  }