IReport generate pdf printing, ireport generate pdf
First download the ireport version, I downloaded the iReport-5.0.4 editing template employees_identity_print_templet
@ RequestMapping ("printEmpPdf") @ ResponseBody public Result printEmpPdf (HttpServletRequest request, HttpServletResponse response, Parameter parameter) {Result result Result = Result. getInitializedResult (); try {parameter = generateParameter (parameter, request); Map <String, Object> map = parameter. getParam (); List <EmployeeVO> employeeVOList = employeeBiz. printmediabarcode (map); // report data source JRDataSource jrDataSource = new JRBeanCollectionDataSource (employeeVOList); // template address String jasperSource_adidas = CommonUtils. getAllMessage ("jdbc", "EMPLOYEES_IDENTITY_PRINT_PDF_TEMPLET") + "success"; 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"); // generate the PDF file storage address String file1_url = CommonUtils. getAllMessage ("jdbc", "IREPORT_FILE_URL"); jr1_exporter extends exporter = new jr1_exporter (); ByteArrayOutputStream baos = new ByteArrayOutputStream (); extends exporter. setParameter (JRExporterParameter. JASPER_PRINT, jasperPrint); export exporter. setParameter (JRExporterParameter. OUTPUT_STREAM, baos); extends exporter. exportReport (); byte [] bytes = baos. toByteArray (); File file = new File (file1_url + fullPath); WebUtil. writeByteArrayToFile (file, bytes); result. baseSucResult (fullPath);} catch (Exception e) {result. baseFailResult ("Maid error", parameter); logger. error ("EmployeeController printEmpPdf error", e) ;}return result ;}
This is the required maven package
<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 Chinese support -->
<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>