赞
踩
基本的东西请看下面链接:
http://www.open-open.com/doc/list/115
看完上面的文档对于基本iReport都了解的差不多了吧!接下来看看中文字体设置
1、先下载需要的字体文件按如下步骤操作:工具——》选项——》font字体
2、将字体导出成jar包
3、将jar打开把里面的 文件考到项目中即可如图:
程序代码:
- package org.share.web;
-
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- import javax.servlet.http.HttpServletRequest;
-
- import net.sf.jasperreports.engine.JRDataSource;
- import net.sf.jasperreports.engine.JREmptyDataSource;
- import net.sf.jasperreports.engine.JasperExportManager;
- import net.sf.jasperreports.engine.JasperFillManager;
- import net.sf.jasperreports.engine.JasperPrint;
- import net.sf.jasperreports.engine.JasperReport;
- import net.sf.jasperreports.engine.JasperRunManager;
- import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
- import net.sf.jasperreports.engine.util.JRLoader;
-
- import org.share.domain.tree.entity.UserInfo;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
-
- @Controller
- @RequestMapping(value="/CreatePDf")
- public class CreatePDf {
-
- @RequestMapping(value="/c",method=RequestMethod.GET)
- public void createFilePdf(HttpServletRequest request){
-
- //路径动态录入需要生产的pdf文件位置
- String fileepath=request.getSession().getServletContext().getRealPath("template/repConReport.pdf");
- FileOutputStream out=null;
- InputStream input=null;
- try{
- //判断文件是否存在
- File f=new File(fileepath);
- if(!f.exists()){
- f.createNewFile();
- }
-
- Map<String, Object> parameters=new HashMap<String, Object>();
- parameters.put("title", "张散弹");
- parameters.put("head", "nininn好好好好");
- //模板文件
- String ctxpathIreport=request.getSession().getServletContext().getRealPath("jasper/report3.jasper");
- File reportFile=new File(ctxpathIreport);
- // JasperReport jasperReport=(JasperReport)JRLoader.loadObject(reportFile);
- // JasperPrint jasperPrint=JasperFillManager.fillReport(jasperReport, parameters);
- input = new FileInputStream(reportFile);
- out=new FileOutputStream(f);
- //前面两个都是流 parameters 设置页面上的数据 最后一个数据源为空
- JasperRunManager.runReportToPdfStream(input, out, parameters, new JREmptyDataSource());
- //JasperExportManager.exportReportToPdfFile(jasperPrint,fileepath);
- }catch (Exception e) {
- e.printStackTrace();
- }finally{
- //关闭流
- try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- input.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
-
- @RequestMapping(value="/cs",method=RequestMethod.GET)
- public void createFilePdfs(HttpServletRequest request){
-
- //路径动态录入需要生产的pdf文件位置
- String fileepath=request.getSession().getServletContext().getRealPath("template/repConReport.pdf");
- //String fileepaths=request.getSession().getServletContext().getRealPath("template/s.html");
- try{
- //判断文件是否存在
- File f=new File(fileepath);
- if(!f.exists()){
- f.createNewFile();
- }
- //自定义数据源
- Map<String, Object> parameters=new HashMap<String, Object>();
- parameters.put("title", "张散弹");
- parameters.put("head", "nininn好好好好");
- List<Map<String, Object>> list=new ArrayList<Map<String,Object>>();
- list.add(parameters);
- list.add(parameters);
- list.add(parameters);
- JRDataSource data= new JRBeanCollectionDataSource(list);
-
- // File reportFile=new File(reportFilePath);
- //模板文件
- String ctxpathIreport=request.getSession().getServletContext().getRealPath("jasper/contract.jasper");
- File reportFile=new File(ctxpathIreport);
- //实际中编译报表很耗时,采用Ireport编译好的报表
- JasperReport jasperReport=(JasperReport)JRLoader.loadObject(reportFile);
- //填充数据
- JasperPrint jasperPrint=JasperFillManager.fillReport(jasperReport, parameters, data);
- //导出pdf文件
- JasperExportManager.exportReportToPdfFile(jasperPrint,fileepath);
- //JasperExportManager.exportReportToHtmlFile(jasperPrint, "");
-
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
-
-
- @RequestMapping(value="/csd",method=RequestMethod.GET)
- public void createFilePdfsd(HttpServletRequest request){
- //路径动态录入需要生产的pdf文件位置
- String fileepath=request.getSession().getServletContext().getRealPath("template/repConReport.pdf");
- try{
- //判断文件是否存在
- File f=new File(fileepath);
- if(!f.exists()){
- f.createNewFile();
- }
- //自定义数据源
- Map<String, Object> parameters=new HashMap<String, Object>();
-
- //获取Javabean list
- List<UserInfo> userList= UserInfo.getListUserInfo();
- //数据源为javabean
- JRDataSource data= new JRBeanCollectionDataSource(userList);
- //设置数据
- parameters.put("beans", data);
- //模板文件
- String ctxpathIreport=request.getSession().getServletContext().getRealPath("jasper/report5.jasper");
- File reportFile=new File(ctxpathIreport);
- //实际中编译报表很耗时,采用Ireport编译好的报表
- JasperReport jasperReport=(JasperReport)JRLoader.loadObject(reportFile);
- //填充数据
- JasperPrint jasperPrint=JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
- //导出pdf文件
- JasperExportManager.exportReportToPdfFile(jasperPrint,fileepath);
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。