http://wuyu.someok.com/blog/dbreport/index.html
条码显示,在birt中最常见的有两种方法:
1、使用条码字体(对pdf无效);
2、用barcode的开源包,生成barcode,然后在报表里用动态地址去取图片。
今晚看birt文档(第 23 章 使用 Java 编写事件处理程序),例子中用java实现了一个LabelEventAdapter的适配器,对标签元素进行事件控制。脑子里灵光一现,似乎条码有着落了。
我的测试例子很简单,继承ImageEventAdapter类,重载onCreate方法,以进行条形码处理
package cn.ynzc.common.birt.test;
import java.io.File;
import java.io.FileOutputStream;
import jbarcodebean.Code128;
import jbarcodebean.JBarcodeBean;
import org.apache.commons.codec.digest.DigestUtils;
import org.eclipse.birt.report.engine.api.script.IReportContext;
import org.eclipse.birt.report.engine.api.script.eventadapter.ImageEventAdapter;
import org.eclipse.birt.report.engine.api.script.instance.IImageInstance;
public class MyLabelClass extends ImageEventAdapter {
public void onCreate(IImageInstance image, IReportContext reportContext) {
try {
//实际应用中,可以使用image.getRowData().getColumnValue("columnname")获得字段值
String code = "ABCDEF123-2222";
//似乎windows文件名中不允许使用“-”等符号,干脆将code进行md5散列处理
File file = new File(System.getProperty("java.io.tmpdir"), DigestUtils.md5Hex(code));
//避免每次都进行条码文件生成
if (!file.exists()) {
JBarcodeBean bb = new JBarcodeBean();
bb.setCodeType(new Code128());
bb.setShowText(true);
bb.setBarcodeHeight(45); //条码高度
bb.setCode(code);
bb.gifEncode(new FileOutputStream(file));
}
image.setFile(file.getAbsolutePath());
}
catch (Exception e) {
e.printStackTrace();
}
}
}
测试用的birt报表文件简单得要死,就往上面扔了个image元素,设置其Event Handler Class为刚才写好的java类,最终得到的rptdesign文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.6" id="1">
<property name="createdBy">Eclipse BIRT Designer Version 2.1.2.v20070205-1728 Build
<20070205-1728>property>
<property name="units">inproperty>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2"/>
</page-setup>
<body>
<image id="4">
<property name="eventHandlerClass">cn.ynzc.common.birt.test.MyLabelClassproperty>
</image>
</body>
</report>
运行测试,条形码出来了
分享到:
相关推荐
如何在birt中显示数据源中html代码如图数据库中的数据是这样的:现在我们要html代码翻译过来操作:放一个text在要展示的地方 如图:双击text 如图选
birt中文帮助文档
任务 9:在 BIRT 报告查看器中预览报告 任务 10:在目录中显示贷记限额范围 聚集数据 如何在表达式构建器中构造聚集表达式 编写表达式 过滤数据 如何过滤行以便从 JDBC 数据源检索数据 如何在数据集级别进行...
BIRT中文帮助文档,BIRT中文帮助文档,BIRT中文帮助文档
birt中文帮助文档.chm birt中文API.chm
birt中文官方资料
在birt中添加js日期控件,文件中已有word文档说明,如有需要不懂得可以加我QQ 356111979
birt中文使用说明。。。。。。。。。。。。。。。。。。。
BIRT中文手册,讲解birt的API及使用实例。
birt Chart在Linux下中文乱码解决方案。
birt报表的页面显示汉化资源文件及汉化过程说明,就是替换birt原有jar包中的英语资源文件为中文资源文件
birt报表详细中文文档,html格式,很详细
Birt中文指南(Birt家园版)(chm) 贡献给大家 2MB
birt中使用script简介
birt 相关部署信息,birt 部署在tomcat 中简单信息
birt中文文档(chm)
BIRT中文指南 eclipse 插件 汉化全中文语言
描述jsp和birt报表的参数传递方法,还不错,转载