Jasper Reports - 自定义条形码生成

发布于 2024-12-27 08:27:15 字数 340 浏览 1 评论 0原文

使用的库/工具: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抠脚大汉 2025-01-03 08:27:15

刚刚尝试了@mdahlman 的答案,它有效。我使用 barcode39 字体"CODE123" >(免费)和 Jaspersoft 烧烤。 Sample Barcode

使用字体设置大小不太容易,但结果是相同的。我在 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. Sample Barcode

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} + "*".

若沐 2025-01-03 08:27:15

鉴于您有 custom-barcode.ttf,它确实可以被视为文本。所以你的步骤是这样的:

  1. 在 iReport 中为 custom-barcode.ttf 创建一个字体扩展。
  2. 使用相关表达式在报告中创建一个文本字段。
  3. 将文本字段的字体设置为“自定义条形码”(或任何您所说的字体扩展名)。调整字体大小以获得所需的输出。

使用条形码的自定义字体可能被认为是一种黑客行为。但它缺乏灵活性,但它的简单性弥补了这一点。

Given that you have custom-barcode.ttf, it really can be treated as text. So your steps are like this:

  1. Create a font extension in iReport for custom-barcode.ttf.
  2. Create a Text Field in the report with a relevant expression.
  3. Set the font for the Text Field to "custom-barcode" (or whatever you call your font extension). Play with the font size to get the desired output.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文