6
votes

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.

2
If you have custom-barcode.ttf, then is it as simple as putting a text element in the report and using this font? - mdahlman
mdahlman, I looked into this before by installing the font through iReport designer and pulling a text field onto the report and setting the pdfEmbedded property. My try wasn't complete, but somehow that didn't make sense. Anyways, I'll try this again and get back to you. - bchetty

2 Answers

3
votes

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

1
votes

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.