Free Support Forum - aspose.com

Rotate a barcode in JasperReports

Hi there,

I managed to add a ASPOSE barcode to my Jasperreport (iReport) but desparately need to rotate the Barcode. (My report will have several bar codes on it).

Can you please provide me with a code sample for my Jasper XML file or work around?

Thanks in advance

I managed to figure out a solution myself and would like to post it back here so that there is an answer to the question :)

After "installing" the JAR's in iReport and verifying that I could create a "normal" barcode I created a Java class as follows:

package com.pepkorit; import com.aspose.barcode.jr.BarCodeAttributes; import java.awt.*; public class AsposeRotateAttributesFactory { public AsposeRotateAttributesFactory() { super(); } public static BarCodeAttributes Create(String text, String symbology, Color foreColor, Integer rotationAngle) { BarCodeAttributes b = new BarCodeAttributes(); b.setCodeText(text); b.setSymbology(symbology); b.setForeColor(foreColor); b.setCodeTextVisible(false); b.setRotationAngle(rotationAngle); b.setAutoSize(true); return b; } }

I then created a JAR file with the complied class. I placed this in the iReport folder where I'd placed the other JAR's and added my JAR to the iReport classpath.

Then in iReport I changed the "normal" barcode to:





Then, when you run the report the barcode is rotated as expected! :)

Note: this was based on the sample code found at http://www.aspose.com/documentation/jasperreports-exporters/aspose.barcode-for-jasperreports/generate-barcodes-using-barcodeattributesfactory.html