天天看點

iReport3.0+MyEclipse8.5生成PDF檔案

1.啟動iReport3,然後建立名為firstReport的新檔:

  點選"檔案"-->"開啟新檔"-->報表名稱:"firstReport"

iReport3.0+MyEclipse8.5生成PDF檔案

2.點選工具欄上的

iReport3.0+MyEclipse8.5生成PDF檔案

圖示,然後分别在title和columnHeader欄上輸入報表标題和列名

iReport3.0+MyEclipse8.5生成PDF檔案

3.建立javaBean作為資料源

   點選:"Data"-->"連結/資料來源"-->"New"-->"JavaBeans set data source"

iReport3.0+MyEclipse8.5生成PDF檔案

輸入資料來源名稱Name: JavaBean_ITSTAR

iReport3.0+MyEclipse8.5生成PDF檔案

4.建立web項目并釋出:(Struts1+Hibernate3+Spring2.5), 并釋出。

iReport3.0+MyEclipse8.5生成PDF檔案

5.将iReport的開發包拷進web工程的lib目錄下。

   iText-2.1.0.jar      

   iTextAsian.jar

   jasperreports-3.0.1.jar

   jfreechart-1.0.0.jar

   jcommon-1.0.0.jar

6.設定iReport中各種格式輸出的系統路徑(在這裡此步驟可以不要)

點選"Options"-->"選項"-->"External Programs"

iReport3.0+MyEclipse8.5生成PDF檔案

7.處理PDF中文問題(對于PDF檔案必須處理)

   點選:"格式化"-->"報表類型"-->"myreport1 字型"-->"建立"

iReport3.0+MyEclipse8.5生成PDF檔案

8.設定iReport的ClassPath路徑,讓iReport能找到這個JavaBean

  單擊:"Options"-->Classpath-->添加檔案夾(添加釋出了的工程的WEB-INF/classes檔案夾)-->Sava Classpath

iReport3.0+MyEclipse8.5生成PDF檔案

7.在detail欄中拖拽JavaBean屬性進myreport1文檔中,職稱這個報表。

iReport3.0+MyEclipse8.5生成PDF檔案

10 查詢JavaBean資料源,生成Field字段

  單擊:"Data"-->"報表查詢"-->"JavaBean Data Source"-->"填寫class name(edu.pojos.User2)"-->Read attributes-->選中Field-->Add Selected Field(s)-->OK

iReport3.0+MyEclipse8.5生成PDF檔案

11. 将編譯生成的firstReport.jasper檔案拷如web工程中

iReport3.0+MyEclipse8.5生成PDF檔案

12. 編寫程式,當以下載下傳的方式将User2中的資料轉化為PDF格式

publicclass ReportActionextends

DispatchAction{

    private User2Serviceuser2Service;

    publicvoid setUser2Service(User2Service user2Service)

{

       this.user2Service

= user2Service;

    }

public ActionForward topdf(ActionMapping mapping, ActionForm form,

 HttpServletRequest request, HttpServletResponse response)

       throws IOException,JRException{

 //集合 資料源

 List<User2>

list =user2Service.getAllUser2();

 JRBeanCollectionDataSource

dataSource = new JRBeanCollectionDataSource(list);

  //轉真實路徑

 InputStream

in = this.getClass().getResourceAsStream("/edu/report/firstReport.jasper");

 //填充

 /**

 * JasperFillManager.fillreport(InputStream inputStream,Map parameters,JRDataSource dataSource)

 **/

  JasperPrint

print = JasperFillManager.fillReport(in,null,

dataSource);

  //導出

  byte[]

data = JasperExportManager.exportReportToPdf(print);

  //輸出格式為pdf

  response.setContentType("application/pdf");

  //彈出下載下傳框

  response.setHeader("Content-Disposition","attachment;filename=user2.pdf");

  //輸出

  response.getOutputStream().write(data);

  return

null;

}