I'm created jrxml
using iReport
and generating barcode using barcode4j
.
Goal:
Output barcode with numeric value which has asterisks.
Looks something like below.
||||||||||
*123456*
barcode section of jrxml:
<componentElement>
<reportElement x="29" y="4" width="209" height="32"/>
<jr:Code39 xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" textPosition="bottom">
<jr:codeExpression>
<![CDATA["*" + $P{barCode} + "*"]]>
</jr:codeExpression>
</jr:Code39>
</componentElement>
The code above runs fine except the output barcode does not have asterisk.
So it looks like:
|||||||||
123456
The trick was to set extendedCharSetEnabled attribute to true.
I got the idea from following sites:
http://barcode4j.sourceforge.net/2.1/symbol-code39.html
So the whole barcode xml part looks like this:
<componentElement>
<reportElement x="29" y="4" width="209" height="32"/>
<jr:Code39 xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"
textPosition="bottom"
extendedCharSetEnabled="true">
<jr:codeExpression>
<![CDATA["*" + $P{barCode} + "*"]]>
</jr:codeExpression>
</jr:Code39>
</componentElement>
UPDATE:
Due to the solution above would output barcode which contains asterisks when scanned.
The true solution is to use displayStartStop attribute and set it to true. And remove asterisk concatenation from CDATA area.
<componentElement>
<reportElement x="29" y="4" width="209" height="32"/>
<jr:Code39 xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"
textPosition="bottom"
displayStartStop="true">
<jr:codeExpression>
<![CDATA[$P{barCode}]]>
</jr:codeExpression>
</jr:Code39>
</componentElement>
NOTE:
Don't use extendedCharSetEnabled attribute together with displayStartStop as asterisks won't show up.