浠婃櫄鐪媌irt鏂囨。錛堢 23 绔?浣跨敤 Java 緙栧啓浜嬩歡澶勭悊紼嬪簭錛夛紝渚嬪瓙涓敤java瀹炵幇浜嗕竴涓狶abelEventAdapter鐨勯傞厤鍣紝瀵規爣絳懼厓绱犺繘琛屼簨浠舵帶鍒躲傝剳瀛愰噷鐏靛厜涓鐜幫紝浼間箮鏉$爜鏈夌潃钀戒簡銆?br />
鎴戠殑嫻嬭瘯渚嬪瓙寰堢畝鍗曪紝緇ф壙ImageEventAdapter綾伙紝閲嶈澆onCreate鏂規硶錛屼互榪涜鏉″艦鐮佸鐞?br />
聽1聽package聽cn.ynzc.common.birt.test;
聽2聽
聽3聽import聽java.io.File;
聽4聽import聽java.io.FileOutputStream;
聽5聽
聽6聽import聽jbarcodebean.Code128;
聽7聽import聽jbarcodebean.JBarcodeBean;
聽8聽
聽9聽import聽org.apache.commons.codec.digest.DigestUtils;
10聽import聽org.eclipse.birt.report.engine.api.script.IReportContext;
11聽import聽org.eclipse.birt.report.engine.api.script.eventadapter.ImageEventAdapter;
12聽import聽org.eclipse.birt.report.engine.api.script.instance.IImageInstance;
13聽
14聽public聽class聽MyLabelClass聽extends聽ImageEventAdapter聽{
15聽
16聽聽聽public聽void聽onCreate(IImageInstance聽image,聽IReportContext聽reportContext)聽{
17聽聽聽聽聽try聽{
18聽聽聽聽聽聽聽//瀹為檯搴旂敤涓紝鍙互浣跨敤image.getRowData().getColumnValue("columnname")鑾峰緱瀛楁鍊?/span>
19聽聽聽聽聽聽聽String聽code聽=聽"ABCDEF123-2222";
20聽聽聽聽聽聽聽//浼間箮windows鏂囦歡鍚嶄腑涓嶅厑璁鎬嬌鐢ㄢ?鈥濈瓑絎﹀彿錛屽共鑴嗗皢code榪涜md5鏁e垪澶勭悊
21聽聽聽聽聽聽聽File聽file聽=聽new聽File(System.getProperty("java.io.tmpdir"),聽DigestUtils.md5Hex(code));
22聽聽聽聽聽聽聽//閬垮厤姣忔閮借繘琛屾潯鐮佹枃浠剁敓鎴?/span>
23聽聽聽聽聽聽聽if聽(!file.exists())聽{
24聽聽聽聽聽聽聽聽聽JBarcodeBean聽bb聽=聽new聽JBarcodeBean();
25聽聽聽聽聽聽聽聽聽bb.setCodeType(new聽Code128());
26聽聽聽聽聽聽聽聽聽bb.setShowText(true);
27聽聽聽聽聽聽聽聽聽bb.setBarcodeHeight(45);聽//鏉$爜楂樺害
28聽聽聽聽聽聽聽聽聽bb.setCode(code);
29聽聽聽聽聽聽聽聽聽bb.gifEncode(new聽FileOutputStream(file));
30聽聽聽聽聽聽聽}
31聽聽聽聽聽聽聽image.setFile(file.getAbsolutePath());
32聽聽聽聽聽}
33聽聽聽聽聽catch聽(Exception聽e)聽{
34聽聽聽聽聽聽聽e.printStackTrace();
35聽聽聽聽聽}
36聽聽聽}
37聽
38聽}
39聽
嫻嬭瘯鐢ㄧ殑birt鎶ヨ〃鏂囦歡綆鍗曞緱瑕佹錛屽氨寰涓婇潰鎵斾簡涓猧mage鍏冪礌錛岃緗叾Event Handler Class涓哄垰鎵嶅啓濂界殑java綾伙紝鏈緇堝緱鍒扮殑rptdesign鏂囦歡鍐呭濡備笅錛?br />聽1聽<?xml聽version="1.0"聽encoding="UTF-8"?>
聽2聽<!--聽Written聽by聽Eclipse聽BIRT聽2.0聽-->
聽3聽<report聽xmlns="http://www.eclipse.org/birt/2005/design"聽version="3.2.6"聽id="1">
聽4聽聽聽聽聽<property聽name="createdBy">Eclipse聽BIRT聽Designer聽Version聽2.1.2.v20070205-1728聽Build聽<20070205-1728></property>
聽5聽聽聽聽聽<property聽name="units">in</property>
聽6聽聽聽聽聽<page-setup>
聽7聽聽聽聽聽聽聽聽聽<simple-master-page聽name="Simple聽MasterPage"聽id="2"/>
聽8聽聽聽聽聽</page-setup>
聽9聽聽聽聽聽<body>
10聽聽聽聽聽聽聽聽聽<image聽id="4">
11聽聽聽聽聽聽聽聽聽聽聽聽聽<property聽name="eventHandlerClass">cn.ynzc.common.birt.test.MyLabelClass</property>
12聽聽聽聽聽聽聽聽聽</image>
13聽聽聽聽聽</body>
14聽</report>
榪愯嫻嬭瘯錛屾潯褰㈢爜鍑烘潵浜?br />
閬楃暀闂錛?br />榪欐鏄皟鐢╫rg.eclipse.birt.report.engine.api.script.instance.IImageInstance.setFile()鏉ヨВ鍐抽棶棰橈紝浠巎avadoc鍙互鐪嬪埌錛孖ImageInstance鏈夊緢澶氭柟娉曞彲浠ヨ皟鐢紝鍏跺畠鏂規硶鍒嗗埆鏈変粈涔堜綔鐢紵姣斿鎴戝皾璇曚簡鍗婂ぉ鐨剆etData(byte[])鏂規硶錛屼竴寮濮嬩互涓烘槸鐢ㄨ繖涓柟娉曠洿鎺ユ妸鍥懼艦鏁版嵁set榪涘幓灝眔k錛岀粨鏋滄湭鎴愬姛銆?br />

]]>