先下载 iReport 版本, 我下载的是 ireport-5.0.4 编辑模板พนักงาน _identity_print_templet
@requestmapping ("printemppdf") @ResponseBody ผลลัพธ์สาธารณะ printemppdf (คำขอ httpservletrequest, การตอบสนอง httpservletResponse, พารามิเตอร์พารามิเตอร์) {ผลลัพธ์ผลลัพธ์ = result.getInitializedResult (); ลอง {parameter = generateParameter (พารามิเตอร์, คำขอ); แผนที่ <สตริงวัตถุ> map = parameter.getParam (); รายการ <SporeEevo> EmployeeVolist = Employeebiz.printpdfbarcode (แผนที่); // 报表数据源 jrdatasource jrdataSource = ใหม่ jrbeancollectionDataSource (EmployeeVolist); // 模板地址 String Jaspersource_adidas = Commonutils.getAllMessage ("jdbc", "พนักงาน _identity_print_pdf_templet")+"พนักงาน _identity_print_templet.jasper"; File ReportFile = ไฟล์ใหม่ (jaspersource_adidas); แผนที่ <สตริงวัตถุ> 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 文件保存地址สตริง filepdfurl = conmonatils.getallmessage ("jdbc", "ireport_file_url"); jrpdfexporter pdfexporter = ใหม่ jrpdfexporter (); ByTeArrayOutputStream BAOS = New ByTeArrayOutputStream (); pdfexporter.setParameter (jrexporterparameter.jasper_print, jasperprint); pdfexporter.setParameter (jrexporterparameter.output_stream, baos); pdfexporter.exportReport (); ไบต์ [] bytes = baos.tobytearray (); ไฟล์ไฟล์ = ไฟล์ใหม่ (filepdfurl+fullPath); WebUtil.WriteByTeArrayTofile (ไฟล์, ไบต์); result.baseSucresult (FullPath); } catch (Exception e) {result.basefailresult ("EmployeeController printemppdf ข้อผิดพลาด", พารามิเตอร์); logger.error ("EmployeeController printemppdf ข้อผิดพลาด", e); } ผลตอบแทนผลลัพธ์; -这是需要的 maven 包
<การพึ่งพา> <roupId> net.sf.jasperreports </groupId> <ratifactid> jasperreports </artifactid> <persion> 5.6.0 </เวอร์ชัน> </การพึ่งพาอาศัย> <การพึ่งพา> <roupid> org.codehaus.grovy <Sersion> 2.2.2 </Servive> </การพึ่งพา> <!-iReport pdf 中文支持-> <การพึ่งพา> <roupId> com.lowagie </groupId> <ratifactid> itextasian </artifactid> <version> 2.1.7.js2 <ArtIfactId> itext </artifactId> <persion> 2.1.7.js2 </เวอร์ชัน> </การพึ่งพา> <การพึ่งพา> <roupId> net.sourceforge.barbecue </groupid> <ratifactid> barbecue </artifactid> <ArtIfactId> iReport-utils </artifactid> <sersion> 2.0.1 </เวอร์ชัน> </การพึ่งพา> <การพึ่งพา> <roupId> คอมมอนส์คอลเลคชั่น </groupId> <ArtIfactId> Commons-Digester </artifactId> <Sersion> 1.8 </Servent> </dercendency>
以上这篇 ireport 生成 pdf 打印的实例代码就是小编分享给大家的全部内容了, 希望能给大家一个参考, 也希望大家多多支持武林网。也希望大家多多支持武林网。