Barcode creation in Jasper report: n is not a valid character for Standard 2 of 5 encoding - jasper-reports

Got the below error while i'm trying to create Barcode using Ireport 1.2.3
Error filling print...
java.lang.RuntimeException: n is not a valid character for Standard 2 of 5 encoding
    at it.businesslogic.ireport.barcode.BcImage.getBarcodeImage(BcImage.java:73)
    at PrintIDCardreport_1452662388727_145783.evaluate(PrintIDCardreport_1452662388727_145783:198)
    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:172)
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:556)
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:524)
    at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:952)
    at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:420)
    at net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:403)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:275)
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:399)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:1289)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:631)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:228)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:750)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:666)
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:517)
    at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:680)
    at java.lang.Thread.run(Unknown Source)
Code for barcode creation:
<image scaleImage="FillFrame" vAlign="Middle" hAlign="Center" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Opaque"
x="32"
y="123"
width="50"
height="10"
forecolor="#000000"
backcolor="#FFFFFF"
key="barcode-1"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<graphicElement stretchType="NoStretch" pen="None" fill="Solid" />
<imageExpression class="java.awt.Image"><![CDATA[it.businesslogic.ireport.barcode.BcImage.getBarcodeImage(13,$F{subjectno1},false,false,null,0,0)]]></imageExpression>
</image>
Used jar files: barbecue-1.1.jar, ireport.jar.
I can able print barcode for static barcode expression.

See the value of $F{subjectno1} variable for letters.
As stated here 2 of 5 barcode standard is only for encoding digits.
If You must have letters in it, check code 128 standard instead.

Related

Jasper Report Text Field gets cut

<band height="20">
<textField textAdjust="StretchHeight">
<reportElement positionType="Float" x="10" y="0" width="545" height="20" uuid="835e5c50-820a-48e7-aa71-b0e5fea3737f">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<box bottomPadding="10">
<pen lineWidth="0.0"/>
</box>
<textElement textAlignment="Justified" markup="none">
<font fontName="Helvetica Neue" size="8.7"/>
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA["RAY ENGINEERING PRIVATE LIMITED mainly deals in products such as GENERAL CONSTRUCTION SERVICES OF HIGHWAYS, STREETS, ROADS, RAILWAYS AND AIRFIELD RUNWAYS, BRIDGES AND TUNNELS (37.32%),CONSTRUCTION SERVICES OF OTHER NON-RESIDENTIAL BUILDINGS SUCH AS EDUCATIONAL INSTITUTIONS,HOSPITALS, CLINICS INCLUDING VERTINARY CLINICS, RELIGIOUS ESTABLISHMENTS, COURTS, PRISONS, MUSEUMS AND OTHER SIMILAR BUILDINGS (16.22%),GENERAL CONSTRUCTION SERVICES OF HARBOURS, WATERWAYS, DAMS, WATER MAINS AND LINES & IRRIGATION AND OTHER WATERWORKS (12.48%)"]]></textFieldExpression>
</textField>
</band>
The whole text is not getting printed . It gets cut after OTHER .
If i add more words in the end after (12.48%) it starts displaying the whole text.
This unusual issue seems to due to a bug in jasper library as i have tried every aspect to correct this.

Dynamic content in text field in JRXML file

Below is the code snippet
<staticText>
<reportElement key="staticText-2" mode="Opaque" x="381" y="242" width="79" height="18" forecolor="#000000" backcolor="#FFFFFF" uuid="4ec23e25-c8d9-4941-bd81-777aff6c08a7">
<reportElement/>
<text><![CDATA[14.01.2019]]></text>
</staticText>
Each month we need to change the date in JRXML file manually <text><![CDATA[14.01.2019]]></text> as 14.11,14,12 etc.
How can I automate this feature? Like code will read the current system date, once it reaches 14th of the month , automatically the date will change in jrxml file as well?
Please help.
You could turn the staticText into a textField where you could use an expression based on JasperReports built-in date/time functions, like so:
<textField>
<reportElement key="staticText-2" mode="Opaque" x="381" y="242" width="79" height="18" forecolor="#000000" backcolor="#FFFFFF" uuid="4ec23e25-c8d9-4941-bd81-777aff6c08a7"/>
<textFieldExpression><![CDATA[DATEFORMAT(EDATE($P{AccountingDate}, 1), "14.MM.yyyy")]]></textFieldExpression>
</textField>

Text truncated on JasperReports

I have a JasperReports's report within an application that is truncating text and I am unsure how to get it to display the full name.
The code snippet below shows that I have included isStretchWithOverflow="true":
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="353" y="0" width="79" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{acname}]]></textFieldExpression>
</textField>
The JasperReports's image shows incorrect values. One of these should read: 'Double Time Pay - Bill Regular' and the other 'Double Time Pay - Bill Overtime'.

iReport pageHeader Image issue

I am using iReport 3.0.0 , presently trying to make a simple change replace image inside a pageHeader with another , but the issue is the new image doesnt fit in.
The band height is 100
old image is png format, 217 x 132 ,and it is inside image element width="190" height="70" ( and this worked fine )
new image is png format, 192 x 130 and is inside image element width="103" height="100"
The issue is for new image there is a v small portion of the image in bottom is not showing up , i changed the height from 70 to 100 , still the same issue.
Any pointers appreciated
OLD CODE IS
<pageHeader>
<band height="100" isSplitAllowed="true" >
<image evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement x="0" y="12" width="190" height="70" key="image-2"/>
<box></box>
<graphicElement stretchType="NoStretch"/>
<imageExpression class="java.lang.String"><![CDATA[$P{REPORT_BASE_DIR}+"Old_logo.png"]]></imageExpression>
</image>
</band>
</pageHeader>
NEW Code IS
<pageHeader>
<band height="100" isSplitAllowed="true" >
<image evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement x="379" y="0" width="103" height="100" key="image-2"/>
<box></box>
<graphicElement stretchType="NoStretch"/>
<imageExpression class="java.lang.String"><![CDATA[$P{REPORT_BASE_DIR}+"New_Logo.png"]]></imageExpression>
</image>
What am i doing wrong ??
Whats is your ireport version?
I tried it with the examples that IDE provides :
Example 1: https://gist.github.com/64fbf51838e648c28a76.git
<image>
<reportElement x="2" y="0" width="118" height="132"/>
<imageExpression><![CDATA["tree1.png"]]></imageExpression>
</image>
Example 2: https://gist.github.com/1a97fa35e63cabb2f8e7.git
<image>
<reportElement x="275" y="0" width="300" height="64"/>
<imageExpression><![CDATA["leaf_banner_red.png"]]></imageExpression>
</image>
I think is your <box> tag or something diferent to this examples.

Formatting/Pattern issue - Appending the Int with text is causing formatting error

So I am running into issues with JasperReports pattern field. I have created a cross tab and I need all $F{ScoreMeasure} to have two decimal places and appended with a "%" sign. So for example a cell for the $F{ScoreMeasure} in the crosstab should show 25.42%.
The issue I have come across is I appended the "%" sign by adding it to the text field expression:$V{ScoreMeasure}+"%". This works fine with whole numbers.
When I try add the two decimal places by adding the pattern #,##0.00 and run the report I get some fields have two decimals and others have multiple (up to 8).
If I drop the appended text (+"%") from the text field expression I get the right format. But I cant work out how to get the two?
Here's an extract of when it is working without the "%" appended:
<crosstabCell width="73" height="25" rowTotalGroup="Name">
<cellContents backcolor="#005FB3" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField pattern="#,##0.00">
<reportElement style="Crosstab Data Text" x="0" y="0" width="73" height="25" forecolor="#FFFFFF" uuid="50401fd4-b9b1-4bf2-bd74-9a0f083e77ff"/>
<textElement verticalAlignment="Middle">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$V{ScoreMeasure}
]]></textFieldExpression>
</textField>
</cellContents>
And here it is appended with the text which is breaking the format:
<crosstabCell width="73" height="25" rowTotalGroup="Name">
<cellContents backcolor="#005FB3" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField pattern="#,##0.00">
<reportElement style="Crosstab Data Text" x="0" y="0" width="73" height="25" forecolor="#FFFFFF" uuid="50401fd4-b9b1-4bf2-bd74-9a0f083e77ff"/>
<textElement verticalAlignment="Middle">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$V{ScoreMeasure}+"%"
]]></textFieldExpression>
</textField>
</cellContents>
Anyone come across this? Any suggestions on how to fix?
Okay so the solution was in the pattern I selected "Custom Format" I then added the pattern for two decimal places ###0.00 and tried appending it with the % sign. So my custom pattern looked like ###0.00%;-###0.00%.
But when this is run it multiplied the figure bu 100. It turns out "The presence of the percentage character in the pattern causes the value to be multiplied by 100 before being formatted."
So in order to avoid this you add quotes around the % sign. So your final pattern looks like this: ###0.00'%';-###0.00'%'
When run you will then get your two decimal place with the % sign
How about clicking on the field you want to customized.
Go to Properties
Go to Pattern then click on the Number -> click on Decimal for 2 spaces
Then Press OK.
Then go back to the Pattern again and go to Custom Format.
Then put a percentage in the text field for the positive and negative part
Then press ok.
EDIT
How about making the Field a string and then append the percent sign like:
$F{ScoreMeasure}.toString()+"%"