iReport 中的 google.zxing 条码生成器
我想在我的页面中添加条形码并可以预览它。条形码生成器是google.zxing,我的报告工具是iReport。
但我不知道如何在iReport中配置图像的图像表达式
和表达式类
。
I want put a barcode in my page and can preview it. The barcode generator is google.zxing and my reporting tool is iReport.
But i dont know, how to configure Image Expression
and Expression Class
of an image in iReport.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两个关键思想是首先编写一些 Java 代码来创建相关图像,然后设计报告以适当地引用此代码。也许生成图像的最简单方法是在这样的脚本中:
这充满了丑陋的硬编码,但关键思想都显示出来了。然后,您需要像这样定义报告:
选择“某些文本”作为条形码_文本
我添加此内容只是为了强调我的脚本对字段名称
barcode_text
进行了硬编码。 (这很糟糕。)BarCodeImage
,类型为java.awt.image.BufferedImage
,具有计算System
。该名称也在脚本中被硬编码。 (这同样糟糕。)
$V{BarCodeImage}
将 Image 元素添加到报表中。结果是在生成的 JasperReport 中生成一个快乐的 QR 代码:
我记得我见过的一个示例这使事情变得更加干净。它实际上包含一个很好的插件,因此您可以轻松地将这个功能安装到 iReport 中,并且花费最少的精力。如果我能找到它,那么我会更新这篇文章。但在那之前,这至少涵盖了所有关键点。
The two key ideas are first to write a bit of Java code to create the relevant image and then to design the report to reference this code appropriately. Perhaps the simplest way to generate the image is in a scriptlet like this:
That's full of hard-coded ugliness, but the key ideas are all shown. Then you need to define the report like this:
select 'some text' as barcode_text
I included this only to reinforce the point that my scriptlet hard-codes the field name
barcode_text
. (This is bad.)BarCodeImage
of typejava.awt.image.BufferedImage
with calculationSystem
.This name is hard-coded in the scriptlet too. (This is equally bad.)
$V{BarCodeImage}
.The result is a happy happy QR-code in your generated JasperReport:
I recall a sample that I have seen which does things much more cleanly. It actually included a nice plug-in so you could easily install this functionality into iReport with minimal effort. If I can track that down, then I'll update this post. But until then this at least covers all of the critical points.
图像表达式应返回 java.awt.Image 的任何子类。实现此目的的最简单方法是使用您自己的帮助器类来生成图像。您可以创建一个从
String
生成条形码的静态方法,并从 IReport 调用该方法。对于 ZXing,我不知道要使用的方法,但我可以使用 Barbecue 库告诉我使用什么作为 ImageExpression。
MyBarcodeGenerator
类包含方法getFromString(...)
,该方法返回net.sourceforge.barbecue.Barcode
在我的例子中是net .sourceforge.barbecue.linear.code39.Code39Barcode
Expression Class
被忽略。--编辑:
要在 zxing 中对图像进行编码,您应该使用
MatrixToImageWriter
以下代码将 QRCode 编码到 BufferedImage 中,您可以在“图像表达式”字段中使用它:
The image expression should return any subclass of
java.awt.Image
. The easiest way to achieve this is to use your own helper class to generate the Image. You can create a static method that generates a barcode from aString
and call that method from IReport.In the case of ZXing I don't know the method to use, but I can tell what I use as ImageExpression using the Barbecue library.
MyBarcodeGenerator
class contains the methodgetFromString(...)
that returns anet.sourceforge.barbecue.Barcode
in my case anet.sourceforge.barbecue.linear.code39.Code39Barcode
The
Expression Class
is ignored.--Edited:
To encode an Image in zxing you should use
MatrixToImageWriter
The following code will encode a QRCode into a BufferedImage which you can use in the Image Expression field: