JasperReports - Barbecue Sample
Shows how barcodes could be included in reports using the Barbecue component.
Main Features in This Sample
Barcodes (Barbecue Custom Component)
Secondary Features
Barcodes (Barbecue Custom Component)
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
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:2of73of9BooklandCodabarCode128Code128ACode128BCode128CCode39Code39 (Extended)EAN128EAN13GlobalTradeItemNumberInt2of5MonarchNW7PDF417PostNetRandomWeightUPCASCC14ShippingCodeShipmentIdentificationNumberSSCC18Std2of5UCC128UPCAUSD3USD4USPS
drawText- specifies whether the text information should be visible in the generated barcodechecksumRequired- specifies whether the checksum is required for the barcodebarWidth- represents the width (in pixels) of the thinnest bar in the barcodebarHeight- represents the height (in pixels) for the bars in the barcodeevaluationTime- represents the report element evaluation timeevaluationGroup- represents the report element evaluation group namerotation- represents the type of orientation for the barcode object.Allowed values are:NoneLeftRightUpsideDown
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>
...
<element kind="component y="100" width="400" height="50">
<component kind="barbecue" drawText="true" type="Code128">
<codeExpression><![CDATA["JasperReports"]] ></codeExpression>
</component>
</element>
<element kind="component" y="160" width="400" height="50">
<component kind="barbecue" drawText="true" type="Codabar">
<codeExpression><![CDATA[$P{Code}]] ></codeExpression>
</component>
</element>
<element kind="component" y="220" width="400" height="50">
<component kind="barbecue" drawText="true" checksumRequired="true" barWidth="3" barHeight="20" type="Int2of5">
<codeExpression><![CDATA[$P{Code}]] ></codeExpression>
</component>
</element>
<element kind="component" y="280" width="400" height="50">
<component kind="barbecue" type="Std2of5">
<codeExpression><![CDATA[$P{Code}]] ></codeExpression>
</component>
</element>
...
Running the Sample
Running the sample requires the Apache Maven library. Make sure that maven is already installed on your system (version 3.6 or later).
In a command prompt/terminal window set the current folder to demo/samples/barbecue within the JasperReports source project and run the following command:
> mvn clean compile exec:exec@all
It will generate all supported document types containing the sample report in the demo/samples/barbecue/target/reports directory.