您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關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; }
這是需要的maven 包
<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打印”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。