Jasper Reports - Creating a Custom Barcode

Libraries / Tools Used: 1) Jasper Reports 2) iReport 3) Java

I have already created some standard barcodes for my reports, but this time I am trying to create my own barcode for which I have a custom-barcode.ttf font file. Currently, iReport supports 2 barcode libraries - Barcode4j and Barbecue, which do not support the native barcode that I need. Any ideas for starters, without much expense of using any new library (I already use Barcode4j)?

By the way, I know that a similar question ( barcode font ) already exists on this site.

+6
source share
2 answers

Just tried @mdahlman's answer and it worked. I created the value "CODE123" using barcode39 font (free) and Jaspersoft Barbecue. Sample barcode

Setting the size is not very simple using the font, but the result is the same. I checked the barcode using a barcode scanner on my Android phone (you can also see it in the same way). The reason this worked for me is probably the same reason the @bchetty test didn't work, because Barcode39 doesn't have a check digit. This is a translation from 1 to 1, except that a leading and trailing asterisk (*) is added to the data. If you want to use ttf to generate a barcode type that has a check mark, you will need a function (external bank, as you mentioned) to encode it. Barcode39 does not need a function, since it is just "*" + V${data} + "*" .

+2
source

Given that you have custom-barcode.ttf, this really can be thought of as text. So your steps are as follows:

  • Create a font extension in iReport for custom-barcode.ttf.
  • Create a text box in the report with the appropriate expression.
  • Set the font for the custom-barcode text box (or whatever you call it the font extension). Play with the font size to get the desired result.

Using a custom font for a barcode can be considered a bit hacked. But what he lacks in flexibility is offset by simplicity.

+1
source

Source: https://habr.com/ru/post/906201/


All Articles