iReport에서 pdf 인쇄 인스턴스 코드 생성

ireport 버전을 먼저 다운로드합니다. iReport-5.0.4 편집 템플릿employees_identity_print_templet

@RequestMapping("printEmpPdf")
 @ResponseBody
 public Result printEmpPdf(HttpServletRequest request,HttpServletResponse response, Parameter parameter){
 Result result=Result.getInitializedResult();
 try{
  parameter = generateParameter(parameter, request);
  Map<String,Object> map= parameter.getParam();
  List<EmployeeVO> employeeVOList=employeeBiz.printPdfBarcode(map);

  //  
  JRDataSource jrDataSource = new JRBeanCollectionDataSource(employeeVOList);
  // 
  String jasperSource_adidas= CommonUtils.getAllMessage("jdbc","EMPLOYEES_IDENTITY_PRINT_PDF_TEMPLET")+"employees_identity_print_templet.jasper";
  File reportFile = new File(jasperSource_adidas);
  Map<String, Object> param_common=new HashMap<String, Object>();
  param_common.put("subReport",jasperSource_adidas);
  JasperPrint jasperPrint;
  jasperPrint = JasperFillManager.fillReport(reportFile.getPath(), param_common, jrDataSource);
  String fullPath = String.valueOf(System.currentTimeMillis()).concat("_ .pdf"); // PDF 
  String filePdfUrl= CommonUtils.getAllMessage("jdbc","IREPORT_FILE_URL");
  JRPdfExporter pdfExporter = new JRPdfExporter();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
  pdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
  pdfExporter.exportReport();
  byte[] bytes = baos.toByteArray();
  File file=new File(filePdfUrl+fullPath);
  WebUtil.writeByteArrayToFile(file,bytes);
  result.baseSucResult(fullPath);
 }catch (Exception e){
  result.baseFailResult("EmployeeController printEmpPdf error",parameter);
  logger.error("EmployeeController printEmpPdf error",e);
 }
 return result;
 }
이게 필요한 메이븐 가방이에요.

<dependency>
 <groupId>net.sf.jasperreports</groupId>
 <artifactId>jasperreports</artifactId>
 <version>5.6.0</version>
</dependency>
<dependency>
 <groupId>org.codehaus.groovy</groupId>
 <artifactId>groovy-all</artifactId>
 <version>2.2.2</version>
</dependency>

<!-- iReport PDF  -->
<dependency>
 <groupId>com.lowagie</groupId>
 <artifactId>itextasian</artifactId>
 <version>2.1.7.js2</version>
</dependency>
<dependency>
 <groupId>com.lowagie</groupId>
 <artifactId>itext</artifactId>
 <version>2.1.7.js2</version>
</dependency>
<dependency>
 <groupId>net.sourceforge.barbecue</groupId>
 <artifactId>barbecue</artifactId>
 <version>1.5-beta1</version>
</dependency>

<dependency>
 <groupId>ireport</groupId>
 <artifactId>ireport-utils</artifactId>
 <version>2.0.1</version>
</dependency>

<dependency>
 <groupId>commons-collections</groupId>
 <artifactId>commons-collections</artifactId>
 <version>3.2</version>
</dependency>
<dependency>
 <groupId>commons-digester</groupId>
 <artifactId>commons-digester</artifactId>
 <version>1.8</version>
</dependency>
상기 iReport에서 pdf를 생성하여 인쇄한 실례 코드는 바로 편집자가 여러분에게 공유한 모든 내용입니다. 여러분께 참고가 되고 저희를 많이 사랑해 주시기 바랍니다.

좋은 웹페이지 즐겨찾기