Jasper Reports - 自定义条形码生成
使用的库/工具: 1) 贾斯珀报告 2) 报表 3) Java
我已经为我的报告生成了一些标准条形码,但这一次,我尝试生成自定义条形码,为此我有一个字体文件 custom-barcode.ttf。截至目前,iReport 支持 2 个条码库 - Barcode4j 和 Barbecue,但它们不支持我需要的自定义条码。有什么想法可以开始使用,而不需要太多使用新库的开销(我已经在使用 Barcode4j)?
顺便说一句,我知道该网站上已经存在类似的问题(自定义条形码字体)。
Libraries/Tools used:
1) Jasper Reports
2) iReport
3) Java
I've already generated some standard barcodes for my reports, but this time, I'm trying to generate a custom barcode, for which I've a font file custom-barcode.ttf. As of now, iReport supports 2 barcode libraries - Barcode4j and Barbecue, which don't support the custom barcode that I need. Any ideas to get started, without much overhead of using some new library (I'm using Barcode4j already)?
BTW, I'm aware that a similar question (custom barcode font) exists on this site already.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
刚刚尝试了@mdahlman 的答案,它有效。我使用 barcode39 字体"CODE123" >(免费)和 Jaspersoft 烧烤。
使用字体设置大小不太容易,但结果是相同的。我在 Android 手机上使用条形码扫描仪验证了条形码(可以看到它在视觉上也很相似)。这对我有用的原因,可能与 @bchetty 的测试不起作用的原因相同,是因为 Barcode39 没有校验位。它是一对一的转换,只是在数据后附加了前导星号和尾随星号 (*)。如果您想使用 ttf 生成具有校验位的条形码类型,您将需要一个函数(如您提到的外部 jar)对其进行编码。 Barcode39 不需要函数,因为它只是
"*" + V${data} + "*"
。Just tried @mdahlman's answer and it worked. I generated the value
"CODE123"
using a barcode39 font (free) and Jaspersoft Barbecue.Setting the size is not very easy using the font but the result is the same. I verified the barcode using Barcode Scanner on my Android phone (can see it's visually similar too). The reason this worked for me, probably same reason @bchetty's test didn't work, is because Barcode39 doesn't have a check-digit. It is a 1-to-1 translation except with a leading and trailing asterisk (*) appended to the data. If you want to use a ttf to generate a barcode type that has a check-digit you'll need a function (external jar like you mentioned) to encode it. Barcode39 doesn't need a function since it's just
"*" + V${data} + "*"
.鉴于您有 custom-barcode.ttf,它确实可以被视为文本。所以你的步骤是这样的:
使用条形码的自定义字体可能被认为是一种黑客行为。但它缺乏灵活性,但它的简单性弥补了这一点。
Given that you have custom-barcode.ttf, it really can be treated as text. So your steps are like this:
Using a custom font for a barcode could be considered a bit of a hack. But what it lacks in flexibility it makes up for in simplicity.