JasperReports Ultimate Guide - Sample Reference - Schema Reference - Configuration Reference - API (Javadoc)
JasperReports - Barbecue Sample (version 5.6.0) |

Shows how barcodes could be included in reports using the Barbecue component.
Download All Sample Source Files
Browse Sample Source Files on SVN

Main Features in This Sample
| Barcodes (Barbecue Custom Component)
Secondary Features
| Barcodes

top
| Barcodes (Barbecue Custom Component) | Documented by Sanda Zaharia
| Description / Goal |  | Shows how to render barcodes in a report, using the barcode component based on the Barbecue library.
| Since |  | 3.5.2
| The Barbecue Library As shown in the Barcodes section, the use of barcodes became universal. Depending on particular needs, there are several barcode specifications, called symbologies. This sample illustrates how to use the built-in component based on the open source Barbecue library. The `Barbecue` library supports the following barcode formats: `2 of 7 (Codabar)` `3 of 9 (Code 39)` `Bookland` `Codabar` `Code 128` `Code 128A` `Code 128B` `Code 128C` `Code 39` `Code 39 (Extended)` `EAN 128` `EAN 13` `Global Trade Item Number` `Interleave 2 of 5` `Monarch` `NW7` `PDF417` `PostNet` `Random Weight UPCA` `SCC-14 Shipping Code` `Shipment Identification Number` `SSCC-18` `Standard 2 of 5` `UCC 128` `UPCA` `USD-3` `USD-4` `USPS` It also provides support for multiple output formats: `PNG` `GIF` `JPEG` The Barbecue Component According to the barbecue element in the components.xsd schema, to completely determine a barcode, the following pieces are needed: Elements: `codeExpression` - representing the alphanumeric character sequence for the barcode `applicationIdentifierExpression` - useful when the UCCEAN128Barcode class is involved, to distinguis between various barcode providers. `` `` `` `` Attributes: `type` - determines the symbology used to generate the barcode. Allowed values are: `2of7` `3of9` `Bookland` `Codabar` `Code128` `Code128A` `Code128B` `Code128C` `Code39` `Code39 (Extended)` `EAN128` `EAN13` `GlobalTradeItemNumber` `Int2of5` `Monarch` `NW7` `PDF417` `PostNet` `RandomWeightUPCA` `SCC14ShippingCode` `ShipmentIdentificationNumber` `SSCC18` `Std2of5` `UCC128` `UPCA` `USD3` `USD4` `USPS` `drawText` - specifies whether the text information should be visible in the generated barcode `checksumRequired` - specifies whether the checksum is required for the barcode `barWidth` - represents the width (in pixels) of the thinnest bar in the barcode `barHeight` - represents the height (in pixels) for the bars in the barcode `evaluationTime` - represents the report element evaluation time `evaluationGroup` - represents the report element evaluation group name `rotation` - represents the type of orientation for the barcode object.Allowed values are: `None` `Left` `Right` `UpsideDown` The Barbecue Sample The sample shows how can be used the `barbecue` component to compute various barcodes:
    <parameter name="Code" class="java.lang.String">
      <defaultValueExpression><![CDATA["01234567890"]] ></defaultValueExpression>
    </parameter>
    ...
    <componentElement>
      <reportElement x="0" y="100" width="400" height="50"/>
      <c:barbecue xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components"
        xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components
        http://jasperreports.sourceforge.net/xsd/components.xsd"
        type="Code128"
        drawText="true"
        checksumRequired="false">
        <c:codeExpression><![CDATA["JasperReports"]] ></c:codeExpression>
      </c:barbecue>
    </componentElement>
    <componentElement>
      <reportElement x="0" y="160" width="400" height="50"/>
      <c:barbecue xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components"
        xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components
        http://jasperreports.sourceforge.net/xsd/components.xsd"
        type="Codabar"
        drawText="true"
        checksumRequired="false">
        <c:codeExpression><![CDATA[$P{Code}]] ></c:codeExpression>
      </c:barbecue>
    </componentElement>
    <componentElement>
      <reportElement x="0" y="220" width="400" height="50"/>
      <c:barbecue xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components"
        xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components
        http://jasperreports.sourceforge.net/xsd/components.xsd"
        type="Int2of5"
        drawText="true"
        checksumRequired="true"
        barWidth="3"
        barHeight="20">
        <c:codeExpression><![CDATA[$P{Code}]] ></c:codeExpression>
      </c:barbecue>
    </componentElement>
    <componentElement>
      <reportElement x="0" y="280" width="400" height="50"/>
      <c:barbecue xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components"
        xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components
        http://jasperreports.sourceforge.net/xsd/components.xsd"
        type="Std2of5"
        drawText="false"
        checksumRequired="false">
        <c:codeExpression><![CDATA[$P{Code}]] ></c:codeExpression>
      </c:barbecue>
    </componentElement>
    ...
Running the Sample Running the sample requires the Apache Ant library. Make sure that `ant` is already installed on your system (version 1.5 or later). In a command prompt/terminal window set the current folder to `demo/samples/barbecue` within the JasperReports source project and run the `> ant test view` command. It will generate all supported document types containing the sample report in the `demo/samples/barbecue/build/reports` directory. Then the report will open in the JasperReports internal viewer.

© 2001- Jaspersoft Corporation www.jaspersoft.com