Creating QR Barcodes

Producing a QR Barcode

To create a QR barcode with Aspose.BarCode:

  1. Instantiate BarCodeAttributes.
  2. Call the setSymbologyType() method and pass QR.
  3. Call the setCodeText() method to set the data you want to encode.

QR barcode sample

todo:image_alt_text

Java

 public class MyAttributes

{

    public static BarCodeAttributes Create(String text, String symbology)

    {

        BarCodeAttributes b = new BarCodeAttributes();

        b.setCodeText(text);

        b.setSymbology(symbology);

        return b;

    }

}

JRXML

 <image hAlign="Center">

<reportElement x="0" y="600"  width="500" height="250" />

<imageExpression class="net.sf.jasperreports.engine.JRRenderable">

   <![CDATA[new com.aspose.barcode.jr.BarCodeRenderer(MyAttributes.Create(

      "1234567890", "QR")

   )]]>

</imageExpression>

</image>

Error Correction

A QR barcode can withstand certain damage and still be decoded normally. This is decided by the QR barcode’s error correction level during encoding. There are four levels of error correction, from low to high:

  • LevelL. Allows recovery of 7% of the code text.
  • LevelM. Allows recovery of 15% of the code text.
  • LevelQ. Allows recovery of 25% of the code text.
  • LevelH. Allows recovery of 30% of the code text.

QR barcode sample with different error correction levels

todo:image_alt_text

Java

 public class MyAttributes

{

    public static BarCodeAttributes Create(String text, String symbology)

    {

        BarCodeAttributes b = new BarCodeAttributes();

        b.setCodeText(text);

        b.setSymbology(symbology);

        b.setQRErrorLevel(QRErrorLevel.LEVEL_H);

        return b;

    }

}

JRXML

 <image hAlign="Center">

<reportElement x="0" y="600"  width="500" height="250" />

<imageExpression class="net.sf.jasperreports.engine.JRRenderable">

   <![CDATA[new com.aspose.barcode.jr.BarCodeRenderer(MyAttributes.Create(

      "1234567890", "QR")

   )]]>

</imageExpression>

</image>

Rotation

A QR barcode can be read from any direction. The images below show valid QR barcodes with different rotation angles.

QR barcode sample with different rotation angles

todo:image_alt_text

Java

 public class MyAttributes

{

    public static BarCodeAttributes Create(String text, String symbology)

    {

        BarCodeAttributes b = new BarCodeAttributes();

        b.setCodeText(text);

        b.setSymbology(symbology);

        b.setRotationAngle(90f);

        return b;

    }

}

JRXML

 <image hAlign="Center">

<reportElement x="0" y="600"  width="500" height="250" />

<imageExpression class="net.sf.jasperreports.engine.JRRenderable">

   <![CDATA[new com.aspose.barcode.jr.BarCodeRenderer(MyAttributes.Create(

      "1234567890", "QR")

   )]]>

</imageExpression>

</image>