iReport產生pdf列印,ireport產生pdf

來源:互聯網
上載者:User

iReport產生pdf列印,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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.